本文整理汇总了C#中Animal.Average方法的典型用法代码示例。如果您正苦于以下问题:C# Animal.Average方法的具体用法?C# Animal.Average怎么用?C# Animal.Average使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Animal
的用法示例。
在下文中一共展示了Animal.Average方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
Animal[] animals = new Animal[] {
new Tomcat("Pesho", 2),
new Kitten("Mimi", 4),
new Dog("Sharo", 3, Sex.Male),
new Frog("Kermit", 5, Sex.Male)
};
Cat[] cats = new Cat[]
{
new Kitten("Mimi", 2),
new Tomcat("Gosho", 6)
};
Console.WriteLine("# Animals");
foreach (Animal animal in animals)
Console.WriteLine(animal);
Console.WriteLine("# Produce sound");
foreach (ISound animal in animals)
Console.WriteLine(animal.ProduceSound());
Console.WriteLine("# Average");
Console.WriteLine(animals.Average(animal => animal.Age));
Console.WriteLine(cats.Average(cat => cat.Age));
}
示例2: Print
private static void Print(Animal[] animals)
{
foreach (var animal in animals)
{
Console.WriteLine (animal);
}
Console.WriteLine ("Average age : {0} years", (animals.Average (x => x.Age)));
Console.WriteLine ();
}
示例3: CalcAverageLambda
//Get Average by Lambda
static double CalcAverageLambda(Animal[] a)
{
return a.Average(x => x.Age);
}
示例4: AverageAge
public static decimal AverageAge(Animal[] arr)
{
return arr.Average(x => (decimal)x.age);
}
示例5: AverageAge
public static double AverageAge(Animal[] animals)
{
return animals.Average(x => x.Age);
}