Enumerating via interface - performance loss

后端 未结 4 909
情书的邮戳
情书的邮戳 2021-02-13 11:57

I had a little dispute (which was very close to holy war:) ) with my colleage, about the performance of access to list via indeces VS via enumerator. To operat

4条回答
  •  旧巷少年郎
    2021-02-13 12:31

    I suspect there is a performance gain in employing for instead of foreach (at least for primitive types). As far as I know they are nearly equivalent if you perform for and foreach over the same array (not any other structure like lists, this creates some overheads by itself).

    The performance of foreach and for depends on which type of structure you are running for and foreach.

    Please check; For and Foreach comparison

提交回复
热议问题