static void Main() { var myList = new GenericList <int>(); var rd = new Random(); for (var i = 1; i <= 10; i++) { myList.Add(rd.Next(0, 100)); Console.Write($"{myList.Tail.Data} "); } Console.WriteLine(); var sum = 0; var max = int.MinValue; var min = int.MaxValue; myList.ForEach(x => { sum += x; max = Math.Max(max, x); min = Math.Min(min, x); }); Console.WriteLine($"Sum is {sum}, max is {max}, min is {min}"); }
static void Main(string[] args) { int[] array = { 1, 2, 3, 4, 5 }; GenericList <int> gl = new GenericList <int>(); for (int i = 0; i < 5; i++) { gl.Add(array[i]); } int sum = 0, maxValue = gl.Head.Value, minValue = gl.Head.Value; //Action<int> computeSum = x => { sum += x; }; //Action<int> computeMax = x => { maxValue = Math.Max(maxValue, x); }; //Action<int> computeMin = x => { minValue = Math.Min(minValue, x); }; gl.ForEach(x => { Console.Write(x + " "); sum += x; maxValue = Math.Max(maxValue, x); minValue = Math.Min(minValue, x); }); Console.WriteLine(" Sum: " + sum + " Max: " + maxValue + " Min: " + minValue); string stop = Console.ReadLine(); }