How can I work with tuples in a foreach loop?
The following code doesn't work:
foreach Tuple(x, y) in sql.lineparams(lines)
{
}
sql.lineparams(lines) is array of tuples <int, string>
How can I work with tuples in a foreach loop?
The following code doesn't work:
foreach Tuple(x, y) in sql.lineparams(lines)
{
}
sql.lineparams(lines) is array of tuples <int, string>
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))
{
...
}
int,string
was an example. Please let me know the actual return type of that method. –
Angelenaangeleno With C# 7 you can also directly reference the content of the tuple:
foreach ((x xVar, y yVar) in sql.lineparams(lines))
{
}
© 2022 - 2024 — McMap. All rights reserved.