Beispiel #1
0
        static void Main(string[] args)
        {
            GenericList <int> intlist = new GenericList <int>();

            for (int i = 0; i < 10; i++)
            {
                intlist.Add(i);
            }
            Action <int> ListAction = i => Console.WriteLine(i);

            int max = intlist.headData;
            int min = max;
            int sum = 0;

            ListAction += i => { if (i > max)
                                 {
                                     max = i;
                                 }
            };
            ListAction += i => { if (i < min)
                                 {
                                     min = i;
                                 }
            };
            ListAction += i => { sum += i; };

            intlist.ForEach(ListAction);
            Console.WriteLine($"最大值:{ max },最小值:{min},和:{sum}");
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            GenericList <int> intlist = new GenericList <int>();

            for (int x = 0; x < 10; x++)
            {
                intlist.Add(x);
            }

            Action <int> action = delegate(int item)
            {
                Console.WriteLine(item);
            };

            intlist.ForEach(action);
            int max = 0;

            intlist.ForEach(m => {
                if (m > max)
                {
                    max = m;
                }
            });
            Console.WriteLine($"max={max}");
            int min = int.MaxValue;

            intlist.ForEach(m => {
                if (m < min)
                {
                    min = m;
                }
            });
            Console.WriteLine($"min={min}");
            int sum = 0;

            intlist.ForEach(m => sum += m);
            Console.WriteLine($"sum={sum}");
        }