Multidimensional arrays do not implement IEnumerable, or do they?

后端 未结 4 1322
广开言路
广开言路 2021-01-13 14:55

For the reasons that I still do not understand (see this SO question) multidimensional arrays in CLR do not implement IEnumerable. So the following doe

4条回答
  •  执笔经年
    2021-01-13 15:36

    There are two reasons they don't implement it natively in C#:

    • There's more than one way you could do it. Do you want each 'cell', or do you want each 'row'? And how do you define 'row': [], IEnumerable, other? What if there are more than two dimensions? As soon as they pick one way, an army of developers will tell them they should have done it a different way.
    • Thanks to iterator blocks and the yield keyword, it just so easy to implement your own that's specific to your need at the time. Of course, that's a C# construct, but it's not that much harder in VB.

提交回复
热议问题