Enumerator Implementation: Use struct or class?

前端 未结 8 2616
再見小時候
再見小時候 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 18:09

    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...

提交回复
热议问题