本文整理汇总了C#中List.Product方法的典型用法代码示例。如果您正苦于以下问题:C# List.Product方法的具体用法?C# List.Product怎么用?C# List.Product使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类List
的用法示例。
在下文中一共展示了List.Product方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
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());
}
示例2: Main
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());
}
示例3: Main
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
}
示例4: Main
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());
}
示例5: Main
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);
}
示例6: Main
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();
}
示例7: Main
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);
}
示例8: Main
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());
}
示例9: Main
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);
}
示例10: Main
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());
}
示例11: Main
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();
}
示例12: Main
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());
}
示例13: Main
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());*/
}
示例14: Main
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());
}
示例15: Main
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());
}