Enumerator Implementation: Use struct or class?

前端 未结 8 2600
再見小時候
再見小時候 2021-02-19 17:44

I noticed that List defines its enumerator as a struct, while ArrayList defines its enumerator as a class. What\'s t

8条回答
  •  北恋
    北恋 (楼主)
    2021-02-19 17:55

    An enumerator is inherently a changing structure, since it needs to update internal state to move on to the next value in the original collection.

    In my opinion, structs should be immutable, so I would use a class.

提交回复
热议问题