C# Foreach statement does not contain public definition for GetEnumerator

后端 未结 4 1575
孤街浪徒
孤街浪徒 2021-02-07 00:33

I\'m having a problem with a Windows Form application I\'m building in C#. The error is stating \"foreach statement cannot operate on variables of type \'CarBootSale.CarBootSale

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-07 00:44

    You should implement the IEnumerable interface (CarBootSaleList should impl it in your case).

    http://msdn.microsoft.com/en-us/library/system.collections.ienumerable.getenumerator.aspx

    But it is usually easier to subclass System.Collections.ObjectModel.Collection and friends

    http://msdn.microsoft.com/en-us/library/system.collections.objectmodel.aspx

    Your code also seems a bit strange, like you are nesting lists?

提交回复
热议问题