How to make the class as an IEnumerable in C#?

前端 未结 5 1528
长情又很酷
长情又很酷 2020-12-31 01:07

So I\'ve got a class and a generic List inside of it, but it is private.

class Contacts
{
    List contacts;
    ...
}

I wan

5条回答
  •  一个人的身影
    2020-12-31 01:49

    public class Contacts: IEnumerable
    {
         ...... 
        public IEnumerator GetEnumerator()
        {
            return contacts.GetEnumerator();
        }
    }
    

    Should do a trick for you.

提交回复
热议问题