How do I implement IEnumerable in my Dictionary wrapper class that implements IEnumerable?

后端 未结 7 2037
走了就别回头了
走了就别回头了 2021-02-08 12:56

I\'m trying to create a wrapper for a Dictionary.

Dictionary implements IEnumerable

7条回答
  •  失恋的感觉
    2021-02-08 13:45

    You've already had several answers to your main question. I'll answer the question raised in your edit...

    The List class actually has three different GetEnumerator methods: The public method that's called when the compile-time instance is typed as List itself, and two explicit interface implementations to meet the IEnumerable/IEnumerable contracts. The enumerator objects returned by all three methods are all the same List.Enumerator type behind-the-scenes.

    // Public method
    public List.Enumerator GetEnumerator() { /* ... */ }
    
    // IEnumerable explicit interface implementation
    IEnumerator IEnumerable.GetEnumerator() { /* ... */ }
    
    // IEnumerable explicit interface implementation
    IEnumerator IEnumerable.GetEnumerator() { /* ... */ }
    

提交回复
热议问题