In PHP I can do this:
$list = array("element1", "element2");
foreach ($list as $index => $value) {
// do stuff
}
In C# i can write:
var list = new List<string>(){ "element1", "element2" };
foreach (var value in list)
{
// do stuff ()
}
But how can I access the index-value in the C# version?
Found multiple solutions on: foreach with index
I liked both JarredPar’s solution:
and Dan Finch’s solution:
I chose Dan Finch’s method for better code readability.
(And I didn’t need to use
continueorbreak)