1. 程式人生 > >IEnumerable 集合迴圈賦值會不成功!要改為 List 集合迴圈賦值

IEnumerable 集合迴圈賦值會不成功!要改為 List 集合迴圈賦值

        public static void Smo2(ref IEnumerable<AA> list)
        {
            foreach (var item in list)
            {
                Console.WriteLine(item.Price);
            }
            foreach (var item in list)
            {
                if (item.Price == "0")
                {
                    item.Price = "3";//這裡賦值會不成功
                    continue;
                }

            }
            foreach (var item in list)
            {
                Console.WriteLine(item.Price);
            }
        }
        public static void Smo(ref List<AA> list)
        {
            foreach (var item in list)
            {
                Console.WriteLine(item.Price);
            }
            foreach (var item in list)
            {
                if (item.Price == "0")
                {
                    item.Price = "3";//這裡可以賦值成功
                    continue;
                }

            }
            foreach (var item in list)
            {
                Console.WriteLine(item.Price);
            }
        }