Getting the array key in a 'foreach' loop

前端 未结 9 737
别跟我提以往
别跟我提以往 2021-02-03 22:42

How do I get the key of the current element in a foreach loop in C#?

For example:

PHP

foreach ($array as $key => $value)
{
             


        
9条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-03 23:33

    Alas there is no built-in way to do this. Either use a for loop or create a temp variable that you increment on each pass.

提交回复
热议问题