Esempio n. 1
0
        static void Main(string[] args)
        {
            //整型list
            GenericList <int> genericList = new GenericList <int>();
            Random            random      = new Random();

            for (int i = 0; i < 10; i++)
            {
                genericList.Add(random.Next(0, 10));
            }
            //show
            genericList.ForEach(Console.WriteLine);
            //求和
            int sum = 0;

            genericList.ForEach(x => sum += x);

            //求max
            int max = genericList.Head.Data;

            genericList.ForEach(
                x =>
            {
                if (max < x)
                {
                    max = x;
                }
            }
                );

            //求min
            int min = genericList.Head.Data;

            genericList.ForEach(
                x =>
            {
                if (x < min)
                {
                    min = x;
                }
            }
                );

            Console.WriteLine($"sum:{sum}");
            Console.WriteLine($"max:{max}");
            Console.WriteLine($"min:{min}");
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            var list  = new GenericList <int>();
            var total = 0;


            Random random = new Random();

            for (int i = 0; i < 10; i++)
            {
                list.Add(random.Next(20));
            }

            int min;
            int max = min = list.Head.Data;

            list.ForEach(Console.WriteLine);
            list.ForEach(d => total += d);
            Console.WriteLine($"和为{total}");
            list.ForEach(d =>
            {
                if (min > d)
                {
                    min = d;
                }
            });
            Console.WriteLine($"最小值为{min}");
            list.ForEach(d =>
            {
                if (max < d)
                {
                    max = d;
                }
            });
            Console.WriteLine($"最大值为{max}");
        }