C# loop over an array of unknown dimensions

后端 未结 3 428
粉色の甜心
粉色の甜心 2021-01-15 04:23

I want to create an extension method to loop over System.Array with unknown number of dimensions

For now I am using a naive approach:

pu         


        
3条回答
  •  一整个雨季
    2021-01-15 05:18

    You could try a recursive approach, in which you test if the item in the array is itself an array. The for loop logic will be called if the item is iterable, and otherwise you can operate on the item for whatever you need to do. If your object implements ICollection this should be fairly simple.

提交回复
热议问题