static void Main()
        {
            //Testing int
            var numbers = new List<int>();
            for (int i = 1; i < 7; i++)
            {
                numbers.Add(i);
            }

            var resultSumInt = numbers.MySum();
            var resultProductInt = numbers.MyProduct();
            var resultAverageInt = numbers.MyAverage();
            var resultMinInt = numbers.MyMin();
            var resultMaxInt = numbers.MyMax();

            foreach (var number in numbers)
            {
                Console.Write(number);
                Console.Write('|');
            }
            Console.WriteLine("\nSum (int): {0}",resultSumInt);
            Console.WriteLine("Product (int): {0}", resultProductInt);
            Console.WriteLine("Average (int): {0}", resultAverageInt);
            Console.WriteLine("Min (int): {0}", resultMinInt);
            Console.WriteLine("Max (int): {0}", resultMaxInt);

            Console.WriteLine(new string('=',30));

            //Testing double
            var numbersDouble = new List<double>();
            for (int i = 1; i < 7; i++)
            {
                numbersDouble.Add(i*1.2);
            }

            var resultSumDouble = numbersDouble.MySum();
            var resultProductDouble = numbersDouble.MyProduct();
            var resultAverageDouble = numbersDouble.MyAverage();
            var resultMinDouble = numbersDouble.MyMin();
            var resultMaxDouble = numbersDouble.MyMax();

            foreach (var number in numbersDouble)
            {
                Console.Write(number);
                Console.Write('|');
            }
            Console.WriteLine("\nSum (double): {0}", resultSumDouble);
            Console.WriteLine("Product (double): {0}", resultProductDouble);
            Console.WriteLine("Average (double): {0}", resultAverageDouble);
            Console.WriteLine("Min (double): {0}", resultMinDouble);
            Console.WriteLine("Max (double): {0}", resultMaxDouble);

            Console.WriteLine(new string('=', 30));

            //Test with string
            string[] textCollection =  {"DodoJuice", "Pulpi"};
            var maxText = textCollection.MyMax();
            Console.WriteLine(maxText);
        }
Example #2
0
 static void Main()
 {
     List<int> mytestList = new List<int>();
     for (int i = 1; i < 10; i++)
     {
         mytestList.Add(i);
     }
     Console.WriteLine("Sum: {0}", mytestList.Sum());
     Console.WriteLine("Product: {0}", mytestList.Product());
     Console.WriteLine("Average: {0}", mytestList.MyAvg());
     Console.WriteLine("Min: {0}", mytestList.MyMin());
     Console.WriteLine("mMx: {0}", mytestList.MyMax());
 }
Example #3
0
 /// <summary>
 /// Implement a set of extension methods for IEnumerable<T> that implement the following group functions: sum, product, min, max, average.
 /// </summary>
 /// <param name="line"></param>
 public static void Problem2(string line)
 {
     Console.WriteLine("\n" + line + "    Problem 2   " + line + "\n\r");
     List<int> ints = new List<int>() { 1, 3, 6, 8, 9, 2, 5, 6 };
     List<float> floats = new List<float>() { 5.53F, 2.33F, 2.4F, 1.234F, -3.43F };
     List<long> longues = new List<long>() { 414L, 1324L, 32L, 56L };
     List<decimal> decimals = new List<decimal>() { 12.152512M, 2314.12341M, 231.23143M, -12.311M, -23.234M };
     Console.WriteLine("LIST of integers: {0}\nSum {1}\nProduct {2}\nMin {3}\nMax {4}\nAveradge {5}",string.Join(" ",ints), ints.Sum(), ints.Product(), ints.MyMin(), ints.MyMax(), ints.Averadge());
     Console.WriteLine(new string('-', 55));
     Console.WriteLine("LIST of floats: {0}\nSum {1}\nProduct {2}\nMin {3}\nMax {4}\nAveradge {5}", string.Join(" ", floats), floats.Sum(), floats.Product(), floats.MyMin(), floats.MyMax(), floats.Averadge());
     Console.WriteLine(new string('-', 55));
     Console.WriteLine("LIST of longs: {0}\nSum {1}\nProduct {2}\nMin {3}\nMax {4}\nAveradge {5}", string.Join(" ", longues), longues.Sum(), longues.Product(), longues.MyMin(), longues.MyMax(), longues.Averadge());
     Console.WriteLine(new string('-', 55));
     Console.WriteLine("LIST of decimals: {0}\nSum {1}\nProduct {2}\nMin {3}\nMax {4}\nAveradge {5}", string.Join(" ", decimals), decimals.Sum(), decimals.Product(), decimals.MyMin(), decimals.MyMax(), decimals.Averadge());
     // <--! Problem 2 ends here -->
 }