How do I get the key of the current element in a foreach
loop in C#?
For example:
PHP
foreach ($array as $key => $value)
{
echo("$value is assigned to key: $key");
}
What I'm trying to do in C#:
int[] values = { 5, 14, 29, 49, 99, 150, 999 };
foreach (int val in values)
{
if(search <= val && !stop)
{
// Set key to a variable
}
}