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()); }
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()); }
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 }
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()); }
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); }
public void TestMethod1() { // Arrange List <int> list = new List <int> { 1, 3, 5, 4, 7, 8, 9 }; int expectedMaxValue = 9; int expectedMinValue = 1; int expectedSumValue = 37; int expectedProductValue = 30240; int expectedAverageValue = 4320; List <int?> listNullable = new List <int?> { 1, null, 5, 4, 7, 8, null }; int?expactedNullableSum = 25; // Act int actualMinValue = list.Min(); int actualMaxValue = list.Max(); int actualSumValue = list.Sum(); int actualProductValue = list.Product(); int actualAverageValue = list.Average(); int?actualSumNullable = listNullable.Sum(); // Assert Assert.AreEqual(expectedMaxValue, actualMaxValue, "Max Values are not equal"); Assert.AreEqual(expectedMinValue, actualMinValue, "Min Values are not equal"); Assert.AreEqual(expectedSumValue, actualSumValue, "Sum Values are not equal"); Assert.AreEqual(expectedProductValue, actualProductValue, "Product Values are not equal"); Assert.AreEqual(expectedAverageValue, actualAverageValue, "Average Values are not equal"); Assert.AreEqual(expactedNullableSum, actualSumNullable, "Nullable sum values are not equal"); }
/// <summary> /// Builds ASymbol. /// </summary> /// <param name="shape">The shape of the AType.</param> /// <param name="symbolLengths">The lengths of the ASymbols contained by the AType.</param> /// <param name="info">The class containing the informations for importing.</param> /// <returns></returns> private AType BuildSymbolArray(List <int> shape, IEnumerable <int> symbolLengths, ImportInfo info) { AType result = Utils.ANull(); if (shape.Count == 0) { StringBuilder toSymbol = new StringBuilder(); int length = symbolLengths.First(); for (int i = 0; i < length; i++) { toSymbol.Append((char)info.Data[info.DataIndex]); info.DataIndex++; } result = ASymbol.Create(toSymbol.ToString()); } else { List <int> nextShape = (shape.Count > 1) ? shape.GetRange(1, shape.Count - 1) : new List <int>(); int subDimensionLength = nextShape.Product(); for (int i = 0; i < shape[0]; i++) { IEnumerable <int> nextSymbolLengths = symbolLengths.Skip(i * subDimensionLength).Take(subDimensionLength); result.Add(BuildSymbolArray(nextShape, nextSymbolLengths, info)); // advance the bytestream further. } } return(result); }
static void Main() { List <string> listOfStrings = new List <string> { "Let's", "try", "these", "extension", "methods", "and", "see", "if", "they", "work", "properly" }; List <double> listOfDoubles = new List <double> { 1.3, 5.6, 2, 0, 4, 15, 6, 8.2, 0.5, 13 }; // when applied to List<string> methods Min and Max - compare the elements and returns the (min) first in lexicographical order and (max) the last in lexicographical order // mehtod .Sum() works properly and concataenates the elements in the list // methods Product() and Average() cannot be implemented because the operators '*' and '/' cannot be applied on objects of type string Console.WriteLine("Results from the implementation of our extension methods to List<string>"); Console.WriteLine(".Sum() -> {0}", listOfStrings.Sum()); Console.WriteLine(".Min() -> {0}", listOfStrings.Min()); Console.WriteLine(".Max() -> {0}", listOfStrings.Max()); Console.Write(Environment.NewLine); // all extension methods work properly Console.WriteLine("Results from the implementation of our extension methods to List<double>"); Console.WriteLine(".Sum() -> {0}", listOfDoubles.Sum()); Console.WriteLine(".Product() -> {0}", listOfDoubles.Product()); Console.WriteLine(".Average() -> {0}", listOfDoubles.Average()); Console.WriteLine(".Min() -> {0}", listOfDoubles.Min()); Console.WriteLine(".Max() -> {0}", listOfDoubles.Max()); }
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(string[] args) { List <double> listForTest = new List <double> { 2.0, 3.5, 5.0, 6.0, 7.0, 9.0, 11.0, 13.7 }; decimal sum = listForTest.Sum(); Console.WriteLine("Sum {0}", sum); double min = listForTest.Min(); Console.WriteLine("Min {0}", min); double max = listForTest.Max(); Console.WriteLine("Max {0}", max); decimal product = listForTest.Product(); Console.WriteLine("Product {0}", product); double average = listForTest.Average(); Console.WriteLine("Average {0}", average); }
static void Main(string[] args) { List <int> intcheta = new List <int> { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; string duma = "tanq"; Console.WriteLine("Here SubString is in use!: Problem #1"); Console.WriteLine(duma.Substring(1, 2)); Console.WriteLine(); Console.WriteLine("Problem #2"); Console.WriteLine("We sum some integers!"); Console.WriteLine(intcheta.Sum <int>()); Console.WriteLine(); Console.WriteLine("We found whith is the smallest!"); Console.WriteLine(intcheta.Minus <int>()); Console.WriteLine(); Console.WriteLine("We found witch is the biggest!"); Console.WriteLine(intcheta.Max <int>()); Console.WriteLine(); Console.WriteLine("We found avarage value!"); Console.WriteLine(intcheta.Avarage <int>()); Console.WriteLine(); Console.WriteLine("We found the product!"); Console.WriteLine(intcheta.Product <int>()); }
public static void Test() { List <int> someNumbers = new List <int>() { 1, 2, 3, 4, 5 }; Console.WriteLine("List<int> someNumbers = new List<int>() { 1, 2, 3, 4, 5 };"); var sum = someNumbers.Sum(); Console.WriteLine("Sum {0}", sum); var product = someNumbers.Product(); Console.WriteLine("Product {0}", product); var min = someNumbers.Minn(); Console.WriteLine("Min {0}", min); var max = someNumbers.Maxx(); Console.WriteLine("Max {0}", max); var average = someNumbers.Average(); Console.WriteLine("Average {0}", average); }
/// <summary> /// Return the greteast common divisor between all values of a collection. /// </summary> /// <param name="numbers">The numbers that you want to compare divisors.</param> public static int GreatestCommonDivisor(this IReadOnlyList <int> numbers) { int minNumber = numbers.Min(); int[] primes = MyMath.GetPrimesBetween(2, minNumber); List <int> commonDivisors = new List <int>(); for (int i = 0; i < primes.Length; i++) { if (numbers.IsDivisibleBy(primes[i])) { commonDivisors.Add(primes[i]); } } if (commonDivisors.Count > 0) { return(commonDivisors.Product()); } else { return(0); } }
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); }
public static double Solution() { var tolerance = 0.0001; var numerator = new List <int>(); var denominator = new List <int>(); for (int i = 11; i <= 99; i++) { for (int j = i + 1; j <= 99; j++) { var skipCondition = i % 10 == 0 | i % 11 == 0 | j % 10 == 0 | j % 11 == 0; if (!skipCondition) { var x = i.GetDigits().ToHashSet(); var y = j.GetDigits().ToHashSet(); // union - set difference - intersection var digits = (x.Union(y)).Except(x.Intersect(y)).Select(z => (double)z).ToArray(); if (digits.Count() == 2 && Math.Abs((double)i / (double)j - digits[0] / digits[1]) < tolerance) { numerator.Add(i); denominator.Add(j); } } } } // 16 19 26 49 // 64 95 65 98 return(denominator.Product(x => x) / numerator.Product(x => x)); }
public static void Main(string[] args) { List<int> testList = new List<int>(); testList.Add(1); testList.Add(2); testList.Add(3); testList.Add(4); testList.Add(5); int sum = testList.Sum<int>(); int product = testList.Product<int>(); int min = testList.Min<int>(); int max = testList.Max<int>(); var average = testList.Average(); Console.WriteLine("The sum of {0} is: {1}", string.Join(" + ", testList), sum); Console.WriteLine("The product of {0} is: {1}", string.Join(" * ", testList), product); Console.WriteLine("The minimal item in {0} is: {1}", string.Join(", ", testList), min); Console.WriteLine("The maximal item in {0} is: {1}", string.Join(", ", testList), max); Console.WriteLine("The average of {0} is: {1}", string.Join(", ", testList), average); }
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); }
public static void Main(string[] args) { StringBuilder test = new StringBuilder(5, 10); test.Append('1', 10); Console.WriteLine(test.Substring(5, 5)); List <int> numbers = new List <int> { 5, 21, 4, 7, 3 }; Console.WriteLine(numbers.Sum()); Console.WriteLine(numbers.Min()); Console.WriteLine(numbers.Average()); Console.WriteLine(numbers.Product()); List <Student> students = new List <Student> { new Student("Pesho", "Ivanov", 23), new Student("Ivan", "Peshov", 24), new Student("Georgi", "Georgiev", 25), new Student("Dragan", "Peshev", 17) }; List <Student> newStudents = FirstBeforeLast(students); Console.WriteLine(newStudents.First().firstName); var OrderByAndThenBy = students.OrderBy((student) => student.firstName).ThenBy((student) => student.lastName); OrderByAndThenBy.ToList(); foreach (var student in OrderByAndThenBy) { Console.WriteLine(student.firstName + student.lastName + student.age); } }
public static void Main() { List <int> numbers = new List <int> { 1, 2, 3, 4, 5, 6 }; var sum = numbers.Sum(); Console.WriteLine("Sum: " + sum); var product = numbers.Product(); Console.WriteLine("Product: " + product); var min = numbers.Min(); Console.WriteLine("Min: " + min); var max = numbers.Max(); Console.WriteLine("Max: " + max); var average = numbers.Average(); Console.WriteLine("Average: " + 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(); }
static void Main() { StringBuilder newStr = new StringBuilder("0123456789"); Console.WriteLine("Using StringBuilder.Substring() -> {0}", newStr.Substring(1, 9).ToString()); Console.WriteLine("Using String.Substring() -> {0}\n", newStr.ToString().Substring(1, 9)); List <string> newStringList = new List <string>() { "Pesho", "Gosho", "Bulgaria", "Hello" }; Console.WriteLine("List of strings: function SUM -> {0}", newStringList.Sum().ToString()); Console.WriteLine("List of strings: function MIN -> {0}", newStringList.Min().ToString()); Console.WriteLine("List of strings: function MAX -> {0}", newStringList.Max().ToString()); List <int> newIntList = new List <int>() { 5, 4, 2, 9 }; Console.WriteLine("\nList of int: function SUM -> {0}", newIntList.Sum().ToString()); Console.WriteLine("List of int: function PRODUCT -> {0}", newIntList.Product().ToString()); Console.WriteLine("List of int: function MIN -> {0}", newIntList.Min().ToString()); Console.WriteLine("List of int: function Max -> {0}", newIntList.Max().ToString()); Console.WriteLine("List of int: function AVERAGE -> {0}", newIntList.Avarage().ToString()); }
public static void Main() { var list = new List <int>() { 1, 2, 3, 4, 10, 5, 6, 7, 8 }; var numbers = new List <double>() { 1.05, 2.11, 3.87, 4.14, 9.00, 5.55, 6.13, 7.93, 8.61 }; Console.WriteLine("Sum"); Console.WriteLine(list.Sum()); Console.WriteLine(numbers.Sum()); Console.WriteLine("Product"); Console.WriteLine(list.Product()); Console.WriteLine(numbers.Product()); Console.WriteLine("Min"); Console.WriteLine(list.Min()); Console.WriteLine(numbers.Min()); Console.WriteLine("Max"); Console.WriteLine(list.Max()); Console.WriteLine(numbers.Max()); Console.WriteLine("Average"); Console.WriteLine(list.Average().ToString("F3")); Console.WriteLine(numbers.Average().ToString("F3")); }
static void Main(string[] args) { IEnumerable <int> list = new List <int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; Console.WriteLine("Check for integers"); Console.WriteLine("Sum: {0}", list.Sum()); Console.WriteLine("Product: {0}", list.Product()); Console.WriteLine("Min: {0}", list.Min()); Console.WriteLine("Max: {0}", list.Max()); Console.WriteLine("Average: {0}", list.Average()); Console.WriteLine(); Console.WriteLine("Check for doubles"); IEnumerable <double> list2 = new List <double>() { 1.1, 2.2, 3.2, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9 }; Console.WriteLine("Sum: {0}", list2.Sum()); Console.WriteLine("Product: {0}", list2.Product()); Console.WriteLine("Min: {0}", list2.Min()); Console.WriteLine("Max: {0}", list2.Max()); Console.WriteLine("Average: {0}", list2.Average()); }
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); }
public override AType this[int index] { get { if (index < 0 || this.Length <= index) //if (index >= 0 && this.Length > index) { throw new Error.Index("[]"); } AType item; ValueType indexValue = GetIndex(index); if (!this.items.TryGetValue(indexValue, out item)) { if (this.Rank > 1) { List <int> cuttedShape = this.Shape.GetRange(1, this.Shape.Count - 1); long subDimensionOffset = index * cuttedShape.Product() * this.mappedFile.Size; item = Create(this.mappedFile, this.depth + 1, this.offset + subDimensionOffset); } else { int elementSize = this.mappedFile.Size; int elementOffset = index * elementSize; item = this.mappedFile.ReadCell(this.offset + elementOffset); } this.items.Add(indexValue, item); } return(item); } }
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()); }
public static void Run() { var someCollection = new List <int>() { 1, -6, 16, 8, 35 }; Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("02. IEnumerable extentions"); Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine("Test List containing integers."); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine($"Product:\t{someCollection.Product()}"); Console.WriteLine($"Sum:\t\t{someCollection.Sum()}"); Console.WriteLine($"Avarage:\t{someCollection.Avarage()}"); Console.WriteLine($"Max element:\t{someCollection.Max()}"); Console.WriteLine($"Min element:\t{someCollection.Min()}"); var someArray = new double[] { 1.1, -6.36, 16.78, 8.79, 35.9 }; Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine("Test array containing float-pointing numbers."); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine($"Product:\t{someArray.Product()}"); Console.WriteLine($"Sum:\t\t{someArray.Sum()}"); Console.WriteLine($"Avarage:\t{someArray.Avarage()}"); Console.WriteLine($"Max element:\t{someArray.Max()}"); Console.WriteLine($"Min element:\t{someArray.Min()}"); }
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); }
public void Will_calculate_zero_product_of_an_empty_long_list() { var list = new List <long>(); var product = list.Product(); Assert.Equal(0, product); }
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); }
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(); }
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());*/ }
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()); }
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()); }
public async Task Product_2Times3_Expect6() { IEnumerable <double> list = new List <double>() { 2, 3 }; Assert.Equal(6, list.Product()); }
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(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() { 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()); }
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()); }
public async Task Product_2Times3Times5_Expect30() { IEnumerable <double> list = new List <double>() { 2, 3, 5 }; Assert.Equal(30, list.Product()); }
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()); }
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()); }
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()); }
public void ProductTest() { var data = new List <Int32>() { 2, 3, 4, 5 }; BigInteger expected = 120; Assert.AreEqual(expected, data.Product()); }
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; }
protected override AType ConvertToAObject(byte[] message) { if (message.Length < 56) { throw new ADAPException(ADAPExceptionType.Import); } AType result; List <int> shape = new List <int>(); int rank = BitConverter.ToInt32(message, rankIndex); int index = shapeIndex; ATypes type; for (int i = 0; i < rank; i++) { shape.Add(BitConverter.ToInt32(message, index)); index += 4; } int typeSize; switch (BitConverter.ToInt32(message, typeIndex)) { case 0: type = ATypes.AInteger; typeSize = sizeof(Int32); break; case 1: type = ATypes.AFloat; typeSize = sizeof(Double); break; case 2: type = ATypes.AChar; typeSize = sizeof(Char) / 2; // sizeof(Char) == 2 break; default: throw new ADAPException(ADAPExceptionType.Import); } int expectedLength = typeSize * shape.Product() + dataIndex; if ((type == ATypes.AChar && message.Length != (expectedLength + 1)) || (type != ATypes.AChar && message.Length != expectedLength)) { throw new ADAPException(ADAPExceptionType.Import); } result = ATypeConverter.Instance.BuildArray(shape, ref message, type, dataIndex); return(result); }
static void Main() { var collection = new List <int> { 100, 200, 129783, 12329083, 9831203 }; Console.WriteLine(collection.Sum <int>()); Console.WriteLine(collection.Average <int>()); Console.WriteLine(collection.Product <int>()); Console.WriteLine(collection.Min <int>()); }
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()); }
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()); }
static void Main() { List <int> collection = new List <int> { 1, 2, 3, 4 }; Console.WriteLine(collection.Sum <int>()); Console.WriteLine(collection.Product <int>()); Console.WriteLine(collection.Min <int>()); Console.WriteLine(collection.Max <int>()); Console.WriteLine(collection.Average <int>()); }
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()); }
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; }
static void Main(string[] args) { List <int> collection = new List <int>(new int[] { -2, 17, 7, 1, -6, -12, 8, 11, 3, 4 }); PrintSequence(collection); Console.WriteLine("sum = {0}", collection.Sum()); Console.WriteLine("product = {0}", collection.Product()); Console.WriteLine("min = {0}", collection.Min()); Console.WriteLine("max = {0}", collection.Max()); Console.WriteLine("average = {0}", collection.Average()); }
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()}"); }
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()); }
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!"); }
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()); }
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()); }