在C#中的foreach
循环中,如何获取当前元素的键(key)?
例如:
PHP示例
foreach ($array as $key => $value)
{
echo("$value is assigned to key: $key");
}
我在C#中尝试做什么:
int[] values = { 5, 14, 29, 49, 99, 150, 999 };
foreach (int val in values)
{
if(search <= val && !stop)
{
// Set key to a variable
}
}