Enumerator Implementation: Use struct or class?

前端 未结 4 866
我在风中等你
我在风中等你 2021-02-19 17:46

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

4条回答
  •  感情败类
    2021-02-19 18:18

    Like this others, I would choose a class. Mutable structs are nasty. (And as Jared suggests, I'd use an iterator block. Hand-coding an enumerator is fiddly to get right.)

    See this thread for an example of the list enumerator being a mutable struct causing problems...

提交回复
热议问题