How can i use generic list with foreach?

Posted by Phsika on Stack Overflow See other posts from Stack Overflow or by Phsika
Published on 2010-06-18T05:58:41Z Indexed on 2010/06/18 6:03 UTC
Read the original article Hit count: 305

if i compiled below codes error return foreach loop how can i solve it?

Error:Error 1 foreach statement cannot operate on variables of type 'Sortlist.MyCalisan' because 'Sortlist.MyCalisan' does not contain a public definition for 'GetEnumerator' C:\Users\yusuf.karatoprak\Desktop\ExcelToSql\TestExceltoSql\Sortlist\Program.cs 46 13 Sortlist


        static void EskiMetodlaListele()
        {
            MyCalisan myCalisan = new MyCalisan();
            Calisan calisan = new Calisan();
            calisan.Ad = "ali";
            calisan.SoyAd = "abdullah";
            calisan.ID = 1;

            myCalisan.list.Add(calisan);

            foreach (Calisan item in myCalisan)
            {
                Console.WriteLine(item.Ad.ToString());
            }
        }


    }

   public class Calisan
    {
        public int ID { get; set; }
        public string Ad { get; set; }
        public string SoyAd { get; set; }

    }

   public class MyCalisan
    {
        public List<Calisan> list { get; set; }
        public MyCalisan()
        {
            list = new List();
        }
    }

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET