本文整理汇总了C#中Cat.Average方法的典型用法代码示例。如果您正苦于以下问题:C# Cat.Average方法的具体用法?C# Cat.Average怎么用?C# Cat.Average使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cat
的用法示例。
在下文中一共展示了Cat.Average方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: Main
static void Main()
{
Animal[] dogArray = new Animal[5];
dogArray[0] = new Dog("Sharo", 4, "male");
dogArray[1] = new Dog("Rex", 1, "male");
dogArray[2] = new Dog("Lasi", 10, "male");
dogArray[3] = new Dog("Djinka", 3, "female");
dogArray[4] = new Dog("Princess", 2, "female");
foreach (var animal in dogArray)
{
Console.WriteLine(animal);
}
var dogArrayAvg = dogArray.Average(d => d.Age);
Console.WriteLine("Average dog age: {0:F2}{1}",dogArrayAvg, Environment.NewLine);
Console.WriteLine();
Cat[] catArray = new Cat[5];
catArray[0] = new Kitten("Mici", 3);
catArray[1] = new Tomcat("Tom", 5);
catArray[2] = new Kitten("Grozdanka", 2);
catArray[3] = new Tomcat("Grozdan", 10);
catArray[4] = new Kitten("Micana", 7);
foreach (var cat in catArray)
{
Console.WriteLine(cat);
}
var catArrayAvg = catArray.Average(c => c.Age);
Console.WriteLine("Average cat age: {0:F2}{1}",catArrayAvg, Environment.NewLine);
Console.WriteLine();
Frog[] frogArray = new Frog[5];
frogArray[0] = new Frog("Kyrmit", 4, "male");
frogArray[1] = new Frog("Kyrmita", 2, "female");
frogArray[2] = new Frog("Kyrmin", 6, "male");
frogArray[3] = new Frog("Kyrmina", 3, "female");
frogArray[4] = new Frog("Kyrtin", 8, "male");
foreach (var frog in frogArray)
{
Console.WriteLine(frog);
}
var frogArrayAvg = frogArray.Average(f => f.Age);
Console.WriteLine("Average frog age: {0:F2}{1}", frogArrayAvg, Environment.NewLine);
Console.WriteLine();
}
示例3: Main
static void Main()
{
Cat[] cats = new Cat[5];
cats[0] = new Tomcat("Murry", 2);
cats[1] = new Kitten("Glori", 4, "January");
cats[2] = new Tomcat("Ico", 3, "Orange", "Mice");
cats[3] = new Kitten("Katya", 2, "March");
cats[4] = new Tomcat("Tom", 5);
Console.WriteLine("The average age of the cats is: " + cats.Average(c => c.Age));
Dog doggy = new Dog("Persin", 6, "Male", "English Pointer");
doggy.ProduceSound();
}