本文整理汇总了C#中Cat.ProduceSound方法的典型用法代码示例。如果您正苦于以下问题:C# Cat.ProduceSound方法的具体用法?C# Cat.ProduceSound怎么用?C# Cat.ProduceSound使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cat
的用法示例。
在下文中一共展示了Cat.ProduceSound方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
//
Cat somecat = new Cat("Monika_Cat",4,"female");
somecat.ProduceSound();
Kitten kitten = new Kitten("Vesi_Kitten", 5);
kitten.ProduceSound();
Console.WriteLine(kitten.Sex);
Tomcat tomCat = new Tomcat("Tomas_TomCat", 6);
tomCat.ProduceSound();
Console.WriteLine(tomCat.Sex);
Frog kyrmit = new Frog("Kyrmit_Jabok", 2, "male");
Dog rex = new Dog("Rex_Dog", 7, "male");
Dog hera = new Dog("Hera_Dog", 8, "female");
List<Animal> animalsList = new List<Animal>();
Cat lora = new Cat("Lora_Cat", 3, "female");
animalsList.Add(somecat);
animalsList.Add(kitten);
animalsList.Add(tomCat);
animalsList.Add(kyrmit);
animalsList.Add(rex);
animalsList.Add(hera);
animalsList.Add(lora);
//Average groups age
var animalGroups =
from animal in animalsList
group animal by animal.GetType();
foreach (var animals in animalGroups)
{
Console.WriteLine(animals.myAverage());
}
}
示例2: Main
private static void Main()
{
IList<Animal> animals = new List<Animal>
{
new Cat("Maca",2, Genders.Female),
new Cat("Kotio", 4, Genders.Male),
new Dog("Balkan", 1, Genders.Male),
new Dog("Sharo", 6, Genders.Male),
new Frog("Tinka", 4, Genders.Female),
new Frog("Gruncho", 7, Genders.Male),
new Kitten("Mariika", 2),
new Tomcat("Gancho", 2)
};
var groupAnimals = from animal in animals
group animal by (animal is Cat) ? typeof(Cat) : animal.GetType()
into g
select new { GroupName = g.Key, AverageAge = g.ToList().Average(a => a.Age) };
foreach (var animal in groupAnimals)
{
Console.WriteLine("{0} - average age: {1:N2}", animal.GroupName.Name, animal.AverageAge);
}
Console.WriteLine();
Animal rex = new Dog("Rex", 10, Genders.Male);
Animal gosho = new Cat("Gosho", 5, Genders.Male);
Animal tina = new Frog("Tina", 4, Genders.Female);
rex.ProduceSound();
gosho.ProduceSound();
tina.ProduceSound();
}
示例3: Main
static void Main()
{
Kitten violeta = new Kitten("Violeta", 24, 'F');
violeta.ProduceSound();
Cat violetka = new Cat("Vili", 24, 'F');
violetka.ProduceSound();
Dog ivan = new Dog("Ivan", 23, 'M');
ivan.ProduceSound();
List<Animal> animals = new List<Animal>
{
new Dog("Ivan", 2, 'M'),
new Dog("Rex", 5, 'M'),
new Dog("Laiza", 1, 'F'),
new Frog("Jaba", 3, 'F'),
new Frog("Chervena jaba", 15, 'M'),
new Frog("Kiorava jaba", 7, 'F'),
new Cat("Sivushka", 4 , 'F'),
new Cat("Felix", 8, 'M'),
new Tomcats("Gosho", 2, 'M'),
new Kitten("Kitty", 1, 'F')
};
var cats =
from animal in animals
where animal is Cat
select animal;
Console.WriteLine("Average cats age is: {0:F2}", ((double)cats.Sum(c => c.Age) / cats.Count()));
var dogs =
from animal in animals
where animal is Dog
select animal;
Console.WriteLine("Average dogs age is: {0:F2}", ((double)dogs.Sum(d => d.Age) / dogs.Count()));
var frogs =
from animal in animals
where animal is Frog
select animal;
Console.WriteLine("Average cats age is: {0:F2}", ((double)frogs.Sum(f => f.Age) / frogs.Count()));
Console.WriteLine();
foreach (var animal in animals)
{
animal.ProduceSound();
}
}
示例4: Main
static void Main()
{
Frog f1 = new Frog("Billy", 0.2, "m");
Dog d1 = new Dog("Liza", 4, "f");
Cat c1 = new Cat("Kotaksi", 2, "m");
Kitten k1 = new Kitten("Raya", 1);
Tomcat t1 = new Tomcat("Rijo", 2);
f1.ProduceSound();
d1.ProduceSound();
c1.ProduceSound();
k1.ProduceSound();
t1.ProduceSound();
Console.WriteLine();
Animal[] animals = new Animal[]
{
new Frog("Billy", 0.2, "m"),
new Dog("Liza", 4, "f"),
new Cat("Kotaksi", 2, "m"),
new Kitten("Raya", 1),
new Tomcat("Rijo", 2),
new Frog("Pesho", 2.1, "f"),
new Dog("Beti", 5.4, "f"),
new Cat("Kotka", 2, "f"),
new Kitten("Spaska", 4),
new Tomcat("Gosho", 3),
new Frog("Marmot", 4, "m"),
new Tomcat("Bizen", 0.5),
new Dog("India", 2.5, "f"),
};
animals.
GroupBy(animal => animal.GetType().Name).
Select(group => new
{
name = group.Key,
averageYears = group.Average(animal => animal.Age)
}).
ToList().
ForEach(group => Console.WriteLine("Group: {0}, average age: {1:F2} years!", group.name, group.averageYears));
}
示例5: TestCreatures
public static void TestCreatures()
{
Dog charlie = new Dog("Charlie", 4, true);
Console.WriteLine(charlie);
charlie.ProduceSound();
Console.WriteLine();
Frog quackster = new Frog("Rab", 1, false);
Console.WriteLine(quackster);
quackster.ProduceSound();
Console.WriteLine();
Cat miew = new Cat("Dangleton", 3, false);
Console.WriteLine(miew);
miew.ProduceSound();
Console.WriteLine();
Kitten kitty = new Kitten("KittyCat", 3);
Console.WriteLine(kitty);
kitty.ProduceSound();
Console.WriteLine();
Tomcat tom = new Tomcat("Tom", 2);
Console.WriteLine(tom);
tom.ProduceSound();
}
示例6: Main
static void Main()
{
Dog dog = new Dog("Sparkie", 18, Sex.Male);
Console.WriteLine(dog.ToString());
Frog frog = new Frog("Kermit", 15, Sex.Male);
Console.WriteLine(frog.ToString());
Cat cat = new Cat("TheBigCat", 6, Sex.Female);
Console.WriteLine(cat.ToString());
Kitten kitten = new Kitten("Kittie", 1, Sex.Female);
//Kitten kitten = new Kitten("Kittie", 1, Sex.Male); //incorrect
Console.WriteLine(kitten.ToString());
Tomcat tomcat = new Tomcat("Tom", 5, Sex.Male);
//Tomcat tomcat = new Tomcat("Tom", 5, Sex.Female); // incorrect
Console.WriteLine(tomcat.ToString());
Console.WriteLine();
dog.ProduceSound();
frog.ProduceSound();
cat.ProduceSound();
kitten.ProduceSound();
tomcat.ProduceSound();
Console.WriteLine();
List<Dog> dogs = new List<Dog>();
dogs.Add(new Dog("Sharo", 2, Sex.Male));
dogs.Add(new Dog("Rex", 5, Sex.Male));
dogs.Add(new Dog("Roshla", 3, Sex.Female));
dogs.Add(dog);
double averageAge = dogs.Average(x => x.Age);
Console.WriteLine("Average age of dogs is {0}.", averageAge);
List<Frog> frogs = new List<Frog>();
frogs.Add(new Frog("Toad", 12, Sex.Male));
frogs.Add(new Frog("Big Toad", 8, Sex.Male));
frogs.Add(new Frog("Ugly Frog", 3, Sex.Female));
frogs.Add(frog);
averageAge = frogs.Average(x => x.Age);
Console.WriteLine("Average age of frogs is {0}.", averageAge);
List<Cat> cats = new List<Cat>();
cats.Add(new Cat("TopCat", 10, Sex.Male));
cats.Add(new Cat("Black Cat", 7, Sex.Male));
cats.Add(new Cat("Kittle", 4, Sex.Female));
cats.Add(cat);
averageAge = cats.Average(x => x.Age);
Console.WriteLine("Average age of cats is {0}.", averageAge);
List<Kitten> kittens = new List<Kitten>();
kittens.Add(new Kitten("Huggie", 1, Sex.Female));
kittens.Add(new Kitten("Pussycat", 2.5, Sex.Female));
kittens.Add(new Kitten("Cuttie", 6, Sex.Female));
kittens.Add(kitten);
averageAge = kittens.Average(x => x.Age);
Console.WriteLine("Average age of kittens is {0}.", averageAge);
List<Tomcat> tomcats = new List<Tomcat>();
tomcats.Add(new Tomcat("Dirty Puss", 4, Sex.Male));
tomcats.Add(new Tomcat("Gray Tomcat", 8.5, Sex.Male));
tomcats.Add(new Tomcat("Blackie", 12.5, Sex.Male));
tomcats.Add(tomcat);
averageAge = tomcats.Average(x => x.Age);
Console.WriteLine("Average age of tomcats is {0}.", averageAge);
Console.WriteLine();
}