Using C# foreach tuple

What does the tuple consist of? Types called x and y? In that case, this should be your syntax:

foreach (Tuple<x, y> tuple in sql.lineparams(lines))
{
  ...
}

If the tuple actually consist of other types, like int and string, it will be like this:

foreach (Tuple<int, string> tuple in sql.lineparams(lines))
{
  ...
}

Or, you can let the compiler handle it for you:

foreach (var tuple in sql.lineparams(lines))
{
  ...
}

With C# 7 you can also directly reference the content of the tuple:

foreach ((x xVar, y yVar) in sql.lineparams(lines))
{

}

Tags:

C#

Tuples