internal static void Main(string[] args)
        {
            List<string> peshho = new List<string>();
            peshho.Add("2");
            peshho.Add("12");
            peshho.Add("3");
            peshho.Product();
            Console.WriteLine(peshho.Product());

            Console.WriteLine(peshho.Sum());
            Console.WriteLine(peshho.Average());
        }
Example #2
0
 static void Main()
 {
     var test = new List<int>() { 4, 3, 2, 1};
     var test2 = new List<double>() { 1, 2, 3, 4 };
     Console.WriteLine(test2.Sum());
     Console.WriteLine(test.Product());
 }
Example #3
0
        static void Main()
        {
            List<double> newList = new List<double>();
            newList.Add(1);
            newList.Add(2);
            newList.Add(3);
            newList.Add(4);
            newList.Add(5);
            Console.WriteLine("Elements:");
            for (int i = 0; i < newList.Count; i++)
            {
                Console.WriteLine("newList[{0}] = {1}",i,newList[i]);
            }

            //Try the Sum method
            Console.WriteLine("\nThe sum of all the elements is = {0}",newList.Sum()); //15

            //Try the Product method
            Console.WriteLine("\nThe product of all the elements is = {0}", newList.Product()); //120

            //Try the Max method
            Console.WriteLine("\nThe maximal of all the elements is = {0}", newList.Max()); //5

            //Try the Min method
            Console.WriteLine("\nThe minimal of all the elements is = {0}", newList.Min()); //1

            //Try the Average method
            Console.WriteLine("\nThe average of all the elements is = {0}", newList.Average()); //3
        }
        private static void Main()
        {
            List<string> testOfStrings = new List<string>() { "az", "ti", "nie", "te" };
            List<char> testOfChars = new List<char>() { 'a', 'b', 'c' };
            List<int> num = new List<int>() { 1, 2, 3 };
            List<double> num2 = new List<double>() { 1.1, 2.2, 3.3 };

            Console.WriteLine(num.Sum());
            Console.WriteLine(num2.Sum());
            Console.WriteLine(testOfChars.Sum());
            Console.WriteLine(testOfStrings.Sum());

            // Product example
            Console.WriteLine(num.Product());
            Console.WriteLine(num2.Product());

            // Boom can't calculate product of string
            // Console.WriteLine(testOfStrings.Product());

            // Min example
            Console.WriteLine(num.Min());
            Console.WriteLine(num2.Min());

            //// Max example
            Console.WriteLine(num.Max());
            Console.WriteLine(num2.Max());

            //// Average example
            Console.WriteLine(num.Average());
            Console.WriteLine(num2.Average());
        }
        public static void Main()
        {
            var listOfnNumbers = new List<int>();

            listOfnNumbers.Add(15);
            listOfnNumbers.Add(10);
            listOfnNumbers.Add(5);
            listOfnNumbers.Add(7);
            listOfnNumbers.Add(9);

            string sum = listOfnNumbers.Sum();
            Console.WriteLine("Sum: {0}", sum);

            string product = listOfnNumbers.Product();
            Console.WriteLine("Product: {0}", product);

            var min = listOfnNumbers.Min();
            Console.WriteLine("Min: {0}", min);

            var max = listOfnNumbers.Max();
            Console.WriteLine("Max: {0}", max);

            var average = listOfnNumbers.Average();
            Console.WriteLine("Average: {0}", average);
        }
        static void Main()
        {
            Console.WriteLine("The text is:");
            StringBuilder newString = new StringBuilder();
            newString.Append("Lorem Ipsum е елементарен примерен текст, използван в печатарската и типографската индустрия. Lorem Ipsum е индустриален стандарт от около 1500 година, когато неизвестен печатар взема няколко печатарски букви и ги разбърква, за да напечата с тях книга с примерни шрифтове. Този начин не само е оцелял повече от 5 века, но е навлязъл и в публикуването на електронни издания като е запазен почти без промяна. Популяризиран е през 60те години на 20ти век със издаването на Letraset листи, съдържащи Lorem Ipsum пасажи, популярен е и в наши дни във софтуер за печатни издания като Aldus PageMaker, който включва различни версии на Lorem Ipsum.");
            Console.WriteLine(newString);
            newString = newString.Substring(6, 19);
            Console.WriteLine();
            Console.WriteLine("The substring is:");
            Console.WriteLine(newString);
            Console.WriteLine();
            Console.WriteLine(new string('*', 80));

            Console.WriteLine("The IEnumerable extancions test is: ");
            var arr = new List<double>() { 3.5, 4.2, 7.5, 9.2, 1 };

            Console.WriteLine("The sum is: ");
            Console.WriteLine(arr.Sum());

            Console.WriteLine("The product is: ");
            Console.WriteLine(arr.Product());

            Console.WriteLine("The minimum is: ");
            Console.WriteLine(arr.Min());

            Console.WriteLine("The maximum is: ");
            Console.WriteLine(arr.Max());

            Console.WriteLine("The average is: ");
            Console.WriteLine(arr.Average());
            Console.WriteLine();
            Console.WriteLine(new string('*', 80));
            Console.WriteLine("Students 3task: ");
            Students();
        }
Example #7
0
        public static void Main()
        {
            StringBuilder text = new StringBuilder("Extension substring method test");
            Console.WriteLine("Text: {0}", text);
            StringBuilder testSubstring = text.Substring(10, 10);
            Console.WriteLine("Substring: {0}", testSubstring);

            List<int> listSum = new List<int>{ 3, 4, 5 };
            Console.WriteLine("Items in collection:");
            foreach (var item in listSum)
            {
                Console.Write("{0} ", item);
            }
            Console.WriteLine();
            int sum = listSum.Sum();
            Console.WriteLine("Sum: {0}", sum);

            List<int> listProduct = new List<int> { 3, 4, 5 };
            int product = listProduct.Product();
            Console.WriteLine("Product: {0}", product);

            List<int> listMax = new List<int> { 3, 4, 5 };
            int max = listMax.Max();
            Console.WriteLine("Max: {0}", max);

            List<int> listMin = new List<int> { 3, 4, 5 };
            int min = listMax.Min();
            Console.WriteLine("Min: {0}", min);

            List<int> listavarage = new List<int> { 3, 4, 5 };
            int avarage = listMax.Avarage();
            Console.WriteLine("Avarage: {0}", avarage);
        }
        static void Main()
        {
            string decorationLine = new string('-', 80);
            Console.Write(decorationLine);
            Console.WriteLine("***Finding sum, product, minimal and maximal elements and average of all the");
            Console.WriteLine("elements of an enumeration that implements the interface IEnumerable<T>***");
            Console.Write(decorationLine);
            
            // Testing with integers
            IEnumerable<int> collectionOfIntegers = new List<int>() { 222, 15181, -125197, 12571, -152 };
            Console.WriteLine("Minimum: " + collectionOfIntegers.Min());
            Console.WriteLine("Maximum: " + collectionOfIntegers.Max());
            Console.WriteLine("Average: " + collectionOfIntegers.Average());
            Console.WriteLine("Product: " + collectionOfIntegers.Product());
            Console.WriteLine("Sum: " + collectionOfIntegers.Sum());

            Console.WriteLine();

            // Testing with doubles
            IEnumerable<double> collectionOfDoubles = new double[6] { -22.1, 251.2, -512, 22, -16, 0.1 };
            Console.WriteLine("Minimum: " + collectionOfDoubles.Min());
            Console.WriteLine("Maximum: " + collectionOfDoubles.Max());
            Console.WriteLine("Average: " + collectionOfDoubles.Average());
            Console.WriteLine("Product: " + collectionOfDoubles.Product());
            Console.WriteLine("Sum: " + collectionOfDoubles.Sum());
        }
        static void Main(string[] args)
        {
            //test extension methods for StringBuilder
            StringBuilder sb = new StringBuilder();
            sb.Append("Once a type is defined and compiled into an assembly its definition is, more or less, final");

            //add substring extension method, from index to the end
            StringBuilder substringToEnd = sb.Substring(5);
            Console.WriteLine(substringToEnd.ToString());

            //the extension method from the exercise task
            StringBuilder substring = sb.Substring(5, 6);
            Console.WriteLine(substring.ToString());

            //test IEnumerable extension methods
            List<double> numbers = new List<double>();
            numbers.Add(6.0);
            numbers.Add(10.0);
            numbers.Add(199.5);
            numbers.Add(0.5);
            numbers.Add(7.0);
            numbers.Add(20.0);

            double minElem = numbers.Min();
            double maxElem = numbers.Max();
            double sum = numbers.Sum();
            double average = numbers.Average();
            double product = numbers.Product();

            Console.WriteLine("Min element: " + minElem + "\nMax element: " + maxElem);
            Console.WriteLine("Sum : " + sum);
            Console.WriteLine("Average : " + average);
            Console.WriteLine("Product : " + product);

        }
Example #10
0
    public static void Main()
    {
        // Initializing Test List
        List<int> testList = new List<int>() { 1, 2, 4, 5 };

        // Testing Sum Method
        int sumResult = testList.Sum<int>();
        Console.WriteLine("The sum is: {0}", sumResult);

        // Testing Product Method
        int productResult = testList.Product<int>();
        Console.WriteLine("The product is: {0}", productResult);

        // Testing Min Value Method
        int minValue = testList.Min<int>();
        Console.WriteLine("The min value is: {0}", minValue);

        // Testing Min Value Method
        int maxValue = testList.Max<int>();
        Console.WriteLine("The max value is: {0}", maxValue);

        // Testing Min Value Method
        decimal averageValue = testList.Average<int>();
        Console.WriteLine("The average value is: {0}", averageValue);
    }
        static void Main()
        {
            IEnumerable <int> intArr =new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            IEnumerable<double> dblArr =new[] { 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9 };

            Console.WriteLine("Sum of: ");
            Console.WriteLine("Integer array: {0}", intArr.Sum());
            Console.WriteLine("Double array: {0}", dblArr.Sum());

            Console.WriteLine();
            Console.WriteLine("Product of: ");
            Console.WriteLine("Integer array: {0}", intArr.Product());
            Console.WriteLine("Double array: {0}", dblArr.Product());

            Console.WriteLine();
            Console.WriteLine("Average of: ");
            Console.WriteLine("Integer array: {0}", intArr.Average());
            Console.WriteLine("Double array: {0}", dblArr.Average());

            Console.WriteLine();
            Console.WriteLine("Min of: ");
            Console.WriteLine("Integer array: {0}", intArr.Min());
            Console.WriteLine("Double array: {0}", dblArr.Min());

            Console.WriteLine();
            Console.WriteLine("Max of: ");
            Console.WriteLine("Integer array: {0}", intArr.Max());
            Console.WriteLine("Double array: {0}", dblArr.Max());
        }
        static void Main()
        {
            List<string> stringList = new List<string>()
            {
                "Academy", "Telerik", "Nakov", "Svetlin", "Kostov", "Kolev"
            };

            List<int> intList = new List<int>()
            {
                1, 2, 3, 4, 5
            };

            //Sum tests
            int sumOfIntElements = intList.Sum();
            Console.WriteLine("-----Sum of ints-----");
            Console.WriteLine(sumOfIntElements);

            string sumOfStrings = stringList.Sum();
            Console.WriteLine("\n-----Sum of strings-----");
            Console.WriteLine(sumOfStrings);

            //Product test
            int productOfIntElements = intList.Product();
            Console.WriteLine("\n-----Product of ints-----");
            Console.WriteLine(productOfIntElements);

            //string productOfStrings = stringList.Product(); // Compile time error because i have constraints. 
            Console.WriteLine("\n-----Product of strings-----");
            Console.WriteLine("Compile time error!");

            //Min test
            int minOfIntElements = intList.Min();
            Console.WriteLine("\n-----Min of ints-----");
            Console.WriteLine(minOfIntElements);

            string minOfStrings = stringList.Min();
            Console.WriteLine("\n-----Min of strings-----");
            Console.WriteLine(minOfStrings);

            //Max test
            int maxOfIntElements = intList.Max();
            Console.WriteLine("\n-----Max of ints-----");
            Console.WriteLine(maxOfIntElements);

            string maxOfStrings = stringList.Max();
            Console.WriteLine("\n-----Max of strings-----");
            Console.WriteLine(maxOfStrings);

            //Average test
            int averageOfIntElements = intList.Average();
            Console.WriteLine("\n-----Average of ints-----");
            Console.WriteLine(averageOfIntElements);

            //string averageOfStrings = stringList.Average(); // Compile time error because i have constraints. 
            Console.WriteLine("\n-----Average of strings-----");
            Console.WriteLine("Compile time error!");
            Console.WriteLine();
        }
Example #13
0
 static void Main()
 {
     List<int> some = new List<int> { 1, 3, -7, 1, 10, -9, 2, 9, 22, 4 };
     Console.WriteLine("Sum: " + some.Sum());
     Console.WriteLine("Product: " + some.Product());
     Console.WriteLine("Min: " + some.Min());
     Console.WriteLine("Max: " + some.Max());
     Console.WriteLine("Average: " + some.Average());
 }
Example #14
0
        static void Main()
        {
            List<int> integers = new List<int>() { 1, 2, 3, 4, 5 };
            Console.WriteLine(integers.Sum());              //OK
            Console.WriteLine(integers.Product());          //OK
            Console.WriteLine(integers.Min());              //OK
            Console.WriteLine(integers.Max());              //OK
            Console.WriteLine(integers.Average());          //OK

            Console.WriteLine("----------------------------");

            List<float> floats = new List<float>() { 1.11f, 2.22f, 3.33f, 4.44f, 5.55f };
            Console.WriteLine(floats.Sum());                //OK
            Console.WriteLine(floats.Product());            //OK
            Console.WriteLine(floats.Min());                //OK
            Console.WriteLine(floats.Max());                //OK
            Console.WriteLine(floats.Average());            //OK

            Console.WriteLine("----------------------------");

            List<double> doubles = new List<double>() { 1.111111111111, 2.22222222222, 3.33333333333 };
            Console.WriteLine(doubles.Sum());               //OK
            Console.WriteLine(doubles.Product());           //OK
            Console.WriteLine(doubles.Min());               //OK
            Console.WriteLine(doubles.Max());               //OK
            Console.WriteLine(doubles.Average());           //OK

            Console.WriteLine("----------------------------");

            List<decimal> decimals = new List<decimal>() { 1.111111111111111111111m, 2.222222222222222222222m, 3.33333333333333333333m };
            Console.WriteLine(decimals.Sum()); //OK
            Console.WriteLine(decimals.Product()); //OK
            Console.WriteLine(decimals.Min()); //OK
            Console.WriteLine(decimals.Max()); //OK
            Console.WriteLine(decimals.Average()); //OK

            Console.WriteLine("----------------------------");

            List<decimal> differrentTypes = new List<decimal>() { 1, (decimal)2.22, (decimal)3.33333333333, 4.444444444444444444444444444444444m };//това реално още тук ги каства!!
            Console.WriteLine(differrentTypes.Sum());            //OK
            Console.WriteLine(differrentTypes.Product());        //OK
            Console.WriteLine(differrentTypes.Min());            //OK
            Console.WriteLine(differrentTypes.Max());            //OK
            Console.WriteLine(differrentTypes.Average());        //OK

            Console.WriteLine("----------------------------");

            List<int> empty = new List<int>() { };
            Console.WriteLine(empty.Sum()); //OK
            Console.WriteLine(empty.Product()); //OK
            //Console.WriteLine(empty.Min()); //exception
            //Console.WriteLine(empty.Max()); //exception
            //Console.WriteLine(empty.Average()); //exception

            /*List<char> chars = new List<char>() { 'a', 'b', 'c', 'd' }; //can't cast the chars
            Console.WriteLine(chars.Sum());*/
        }
Example #15
0
 public static void Main()
 {
     List<int> list = new List<int> { 1, 5, 2, 88, 6 };
     Console.WriteLine(list.Sum());
     Console.WriteLine(list.Min());
     Console.WriteLine(list.Max());
     Console.WriteLine(list.Product());
     Console.WriteLine(list.Average());
 }
 static void Main()
 {
     IEnumerable<int> x = new List<int>() { 1, 9, 45, -6 };
     Console.WriteLine(x.Sum());
     Console.WriteLine(x.Product());
     Console.WriteLine(x.Min());
     Console.WriteLine(x.Max());
     Console.WriteLine(x.Average());
 }
Example #17
0
 static void Main()
 {
     List<int> numbers = new List<int> { 5, 3, 8, 1, 11, 13, 9, 2 };
     Console.WriteLine(numbers.Sum());
     Console.WriteLine(numbers.Product());
     Console.WriteLine(numbers.Min());
     Console.WriteLine(numbers.Max());
     Console.WriteLine(numbers.Average());
 }
Example #18
0
 static void Main(string[] args)
 {
     List<int> test = new List<int>{ 1, 1, 3, 4 };
     Console.WriteLine( test.Sum<int>());
     Console.WriteLine(test.Product<int>());
     Console.WriteLine(test.Average<int>());
     Console.WriteLine(test.Min<int>());
     Console.WriteLine(test.Max<int>());
 }
 static void Main(string[] args)
 {
     List<int> list = new List<int>() { 1, 2, 21, 43, 125 };
     Console.WriteLine(list.Sum());
     Console.WriteLine(list.Product());
     Console.WriteLine(list.Max());
     Console.WriteLine(list.Min());
     Console.WriteLine(list.Average());
 }
Example #20
0
 public static void Main()
 {
     List<double> newlist = new List<double>() { 2, 3, 4, 5, 6, 7, 8, 9, 1, 12, 23, 44 };
     Console.WriteLine(newlist.Average());
     Console.WriteLine(newlist.Sum());
     Console.WriteLine(newlist.Product());
     Console.WriteLine(newlist.Min());
     Console.WriteLine(newlist.Max());
 }
Example #21
0
 static void Main(string[] args)
 {
     List<double> l = new List<double>() { 1.5, 0.5, 1.0 };
     Console.WriteLine(l.Min());
     Console.WriteLine(l.Max());
     Console.WriteLine(l.Sum());
     Console.WriteLine(l.Product());
     Console.WriteLine(l.Average());
 }
    private static void Main()
    {
        var collection = new List<decimal> { 17, 1, 15, 99, 6, 7, 3 };

        Console.WriteLine(collection.Max());
        Console.WriteLine(collection.Min());
        Console.WriteLine(collection.Sum());
        Console.WriteLine(collection.Product());
        Console.WriteLine(collection.Average());
    }
        static void Main()
        {
            var list = new List<int> { 2, 8, 15, 9, 52, 98, 11 };

            Console.WriteLine("Sum of elements in collection: " + list.Sum());
            Console.WriteLine("Product of elements in collection: " + list.Product());
            Console.WriteLine("Max element in collection: " + list.Max());
            Console.WriteLine("Min element in collection: " + list.Min());
            Console.WriteLine("Avarage sum of elements in collection: " + list.Avarage());
        }
        public AType BuildArray(List<int> shape, ref byte[] data, ATypes type, int index)
        {
            AType result = Utils.ANull();
            int typeSize;
            ItemConstructDelegate itemConstruct;

            switch (type)
            {
                case ATypes.AInteger:
                    typeSize = sizeof(Int32);
                    itemConstruct = ConstructAInteger;
                    break;
                case ATypes.AChar:
                    typeSize = sizeof(Char) / 2; // FIXMEEE!!!!! sizeof(Char) == 2 in C#!!!!!
                    itemConstruct = ConstructAChar;
                    break;
                case ATypes.AFloat:
                    typeSize = sizeof(Double);
                    itemConstruct = ConstructAFloat;
                    break;
                default:
                    throw new ADAPException(ADAPExceptionType.Import);
            }

            if (data.Length < (typeSize * shape.Product() + index))
            {
                throw new ADAPException(ADAPExceptionType.Import);
            }

            if (shape.Count == 0)
            {
                result = itemConstruct(ref data, index);
            }
            else if (shape.Count == 1)
            {
                for (int i = 0; i < shape[0]; i++)
                {
                    result.Add(itemConstruct(ref data, index));
                    index += typeSize;
                }
            }
            else
            {
                for (int i = 0; i < shape[0]; i++)
                {
                    List<int> nextShape = shape.GetRange(1, shape.Count - 1);
                    int subDimensionLength = nextShape.Product() * typeSize;

                    result.Add(BuildArray(nextShape, ref data, type, index));
                    index += subDimensionLength;
                }
            }

            return result;
        }
Example #25
0
 static void Main()
 {
     List<int> numbers = new List<int>();
     numbers.Add(5);
     numbers.Add(6);
     Console.WriteLine("Max: {0}", numbers.Max());
     Console.WriteLine("Min: {0}", numbers.Min());
     Console.WriteLine("Average: {0}", numbers.Average());
     Console.WriteLine("Sum: {0}", numbers.Sum());
     Console.WriteLine("Product: {0}", numbers.Product());
 }
 private void CalculateHistoricalData(List<EquityOnTime> listProfit, List<float> lstProfit)
 {
     cumulativeReturn = 100 * (listProfit[listProfit.Count - 1].equity - listProfit[0].equity) / listProfit[0].equity;
     cumulativeVAMI = listProfit[listProfit.Count - 1].equity;
     meanReturn = lstProfit.Average() * 100;
     compoundRoRmonth = lstProfit.Product(p => 1 + p);
     compoundRoRmonth = 100 * ((float)Math.Pow(compoundRoRmonth, 1.0f / lstProfit.Count) - 1);
     largestMonthGain = 100 * lstProfit.Max();
     largestMonthLoss = 100 * lstProfit.Min();
     if (largestMonthLoss > 0) largestMonthLoss = 0;
     percentPositiveMonths = 100 * lstProfit.Count(p => p > 0) / (float)lstProfit.Count;
 }
Example #27
0
 static void Main()
 {
     List<int> collection = new List<int>();
     collection.Add(200);
     collection.Add(100);
     collection.Add(170);
     Console.WriteLine($"Sum= {collection.Sum()}");
     Console.WriteLine($"Product= {collection.Product()}");
     Console.WriteLine($"Min= {collection.Min()}");
     Console.WriteLine($"Max= {collection.Max()}");
     Console.WriteLine($"Average= {collection.Average()}");
 }
        public static void Main()
        {
            List<int> numbers = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

            Console.WriteLine("The sum of the collection is: {0}",numbers.Sum());
            Console.WriteLine("The product of the collection is: {0}", numbers.Product());
            Console.WriteLine("The min element in the collection is: {0}", numbers.Min());
            Console.WriteLine("The max element in the collection is: {0}", numbers.Max());
            Console.WriteLine("The average of the collection is: {0}", numbers.Average());
            Console.WriteLine();
            Console.WriteLine("If you want you can try with another IEnumerable collections!");
        }
Example #29
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 #30
0
        private static void IEnumerable_Extensions()
        {
            List<int> numbers = new List<int>();
            numbers.Add(1);
            numbers.Add(2);
            numbers.Add(3);
            numbers.Add(4);

            Console.WriteLine("Max: {0}", numbers.Min());
            Console.WriteLine("Min: {0}", numbers.Max());
            Console.WriteLine("Sum: {0}", numbers.Sum());
            Console.WriteLine("Product: {0}", numbers.Product());
        }