C# - How to implement IEnumerator on a class

后端 未结 3 497
南旧
南旧 2020-12-18 22:29

How to implement IEnumerator on this class so that I can use it in foreach loop.

public class Items
    {
        private Dictionary

        
3条回答
  •  春和景丽
    2020-12-18 22:49

    You don't need to implement IEnumerable or any interface. In order to be able to use your class in a foreach, all that you need is to add an instance method to your class with the follwing signature:

    IEnumerator GetEnumerator()
    

提交回复
热议问题