本文整理汇总了C#中Dog.MakeSound方法的典型用法代码示例。如果您正苦于以下问题:C# Dog.MakeSound方法的具体用法?C# Dog.MakeSound怎么用?C# Dog.MakeSound使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dog
的用法示例。
在下文中一共展示了Dog.MakeSound方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main()
{
Dog lol = new Dog("Ivan", 12, Sex.Male);
lol.MakeSound();
Kitten test = new Kitten("Ivanka", 12, Sex.Female);
Animal[] myZoo =
{
new Cat("Ivanka", 12, Sex.Female),
new Kitten("Ivanka", 12, Sex.Female),
new Frog("Ivanka", 20, Sex.Female),
new Frog("Ivanka", 10, Sex.Female),
new Dog("Ivanka", 12, Sex.Female),
new Cat("Ivanka", 12, Sex.Female),
new Kitten("Ivanka", 12, Sex.Female),
new Frog("Ivanka", 20, Sex.Female),
new Frog("Ivanka", 10, Sex.Female),
new Dog("Ivanka", 12, Sex.Female),
new Cat("Ivanka", 12, Sex.Female),
new Kitten("Ivanka", 12, Sex.Female),
new Frog("Ivanka", 20, Sex.Female),
new Frog("Ivanka", 10, Sex.Female),
new Dog("Ivanka", 12, Sex.Female),
new Cat("Ivanka", 12, Sex.Female),
new Kitten("Ivanka", 12, Sex.Female),
new Frog("Ivanka", 20, Sex.Female),
new Frog("Ivanka", 10, Sex.Female),
new Dog("Ivanka", 12, Sex.Female),
};
Animal.AgeAverage(myZoo);
}
示例2: Main
static void Main(string[] args)
{
Dog firstDog = new Dog(2, "Sharo");
Dog secondDog = new Dog(6, "Djaro");
Dog thirdDog = new Dog(1, "Tobi");
Dog fourthDog = new Dog(5, "Roni");
Dog[] dogs = new Dog[]
{
firstDog, secondDog, thirdDog, fourthDog
};
Console.WriteLine("The average age of the dogs is: {0}", Animal.GetAverageAge(dogs));
firstDog.MakeSound();
Console.WriteLine();
Cat firstCat = new Kitten(1, "Kitty");
Cat secondCat = new Tomcat(2, "Bojko");
Cat thirdCat = new Cat(4, "Myrzel", "male");
Cat[] cats = new Cat[]
{
firstCat,
secondCat,
thirdCat
};
Console.WriteLine("The average age of the cats is: {0}", Animal.GetAverageAge(cats));
Console.WriteLine();
Console.WriteLine("The kitten's name is: {0} ", firstCat.GetName());
Console.WriteLine("The kitten's age is: {0}", firstCat.GetAge());
Console.WriteLine("All kittens are {0}", firstCat.Sex);
firstCat.MakeSound();
Console.WriteLine();
Console.WriteLine("The tomcat's name is: {0}", secondCat.GetName());
Console.WriteLine("All tomcats are {0}", secondCat.Sex);
secondCat.MakeSound();
thirdCat.MakeSound();
Console.WriteLine();
Frog froggy = new Frog(22, "Prince");
froggy.MakeSound();
}
示例3: Main
static void Main()
{
Tomcat tomCat = new Tomcat("Tom", 4, "Siam");
Console.WriteLine(tomCat.Name + " is age " + tomCat.Age + " and breed " + tomCat.Breed + " and is " + tomCat.Gender);
tomCat.MakeSound();
Console.WriteLine();
Kitten pussyCat = new Kitten("Pussy", 2, "Angora");
Console.WriteLine(pussyCat.Name + " is age " + pussyCat.Age + " and breed " + pussyCat.Breed + " and is " + pussyCat.Gender);
pussyCat.MakeSound();
Console.WriteLine();
Dog balkanDog = new Dog("Balkan", 4, Gender.Male, "Bulgarian sheperd");
Console.WriteLine(balkanDog.Name + " is age " + balkanDog.Age + " and breed " + balkanDog.Breed + " and is " + balkanDog.Gender);
balkanDog.MakeSound();
Console.WriteLine();
Frog frogy = new Frog("Sluzestio", 2, Gender.Male);
Console.WriteLine(frogy.Name + " is age " + frogy.Age + " and is " + frogy.Gender);
frogy.MakeSound();
Animal[] animals =
{
new Dog("Murdjo", 8, Gender.Male, "Pomiar"),
new Dog("Sharo", 6, Gender.Male, "German sheper"),
balkanDog,
new Dog("Bonka", 4, Gender.Female, "Bolonka"),
new Frog("Kerkendeto", 2, Gender.Male),
new Frog("Zelenka", 2, Gender.Female),
frogy,
new Kitten("Maca", 2, "Angora"),
pussyCat,
new Tomcat("Ohoboho", 3, "Ulichna prevazhodna"),
tomCat,
};
double averageDogsAge = animals.Where(x => x is Dog).Average(x => x.Age);
double averageFrogsAge = animals.Where(x => x is Frog).Average(x => x.Age);
double averageCatsAge = animals.Where(x => x is Cat).Average(x => x.Age);
Console.WriteLine("Average age of the dogs: {0}", averageDogsAge);
Console.WriteLine("Average age of the frogs: {0}", averageFrogsAge);
Console.WriteLine("Average age of the cats: {0}", averageCatsAge);
}
示例4: Main
static void Main(string[] args)
{
Dog myDog = new Dog("Sharo", 2, "male");
myDog.MakeSound();
Cat kitten = new Kitten("Lola", 4);
Console.WriteLine(kitten.Sex);
kitten.MakeSound(); //Different sound results for the two cats, because one is initiated as a Cat and the other as a Kitten
Kitten secondKitten = new Kitten("Muhla", 1);
secondKitten.MakeSound();
List<Animal> animalList = new List<Animal>();
animalList.Add(new Dog("Burkan", 5, "male"));
animalList.Add(new Dog("Penka", 2, "female"));
animalList.Add(new Kitten("Karma", 1));
animalList.Add(new Kitten("Shusha", 3));
animalList.Add(new Tomcat("Roshko", 6));
animalList.Add(new Frog("Galoshko", 1, "male"));
animalList.Add(new Frog("Zelen", 2, "male"));
var animalsByKind =
(from animal in animalList
group animal by animal.GetType().Name into newGroup
select new
{
animalKind = newGroup.Key,
averageAge =
(from sortedAnimals in newGroup
select sortedAnimals.Age).Average()
});
Console.WriteLine("Animal kinds with average age:");
foreach (var group in animalsByKind)
{
Console.WriteLine(group);
}
}
示例5: Main
static void Main(string[] args)
{
Dog dog = new Dog("Rex", 4, AnimalSex.Male);
Console.WriteLine(dog.MakeSound());
Kitten kitten = new Kitten("Kitty", 1);
Console.WriteLine(kitten.MakeSound());
List<Animal> animals = new List<Animal>() { dog, kitten };
animals.Add(new Dog("Alice", 3, AnimalSex.Female));
animals.Add(new Frog("Terminator", 5, AnimalSex.Male));
animals.Add(new Tomcat("Tom", 2));
Console.WriteLine("\n{0}\n", new string('-', 25));
var getAllKindsOfAnimals = animals.GroupBy(x => x.GetType()); // grouping animals by type( classes )
foreach (var type in getAllKindsOfAnimals)
{
Console.WriteLine("{0}s: Average age = {1}", type.Key.Name, type.Average(x => x.Age));
}
}