static void Main() { Dog[] dogs = new Dog[3]; dogs[0] = new Dog(5, "Rex", Sex.male); dogs[1] = new Dog(2, "Lara", Sex.female); dogs[2] = new Dog(14, "Sharo", Sex.male); double averageDog = AverageAge(dogs); Console.WriteLine("Dog average age: {0:F2}", averageDog); Frog[] frogs = new Frog[3]; frogs[0] = new Frog(1, "Kikerica", Sex.female); frogs[1] = new Frog(2, "Juji", Sex.female); frogs[2] = new Frog(3, "Kermit", Sex.male); double averageFrog = AverageAge(frogs); Console.WriteLine("Frog average age: {0:F2}", averageFrog); Cat[] cats = new Cat[3]; cats[0] = new Cat(5, "Pisio", Sex.male); cats[1] = new Cat(12, "Maca", Sex.female); cats[2] = new Cat(11, "Garfield", Sex.male); double averageCat = AverageAge(cats); Console.WriteLine("Cat average age: {0:F2}", averageCat); Kitten[] kittens = new Kitten[3]; kittens[0] = new Kitten(1, "Pisanka"); kittens[1] = new Kitten(2, "Topcho"); kittens[2] = new Kitten(1, "Puhcho"); double averageKitten = AverageAge(kittens); Console.WriteLine("Kitten average age: {0:F2} ", averageKitten); Tomcat[] tomcats = new Tomcat[3]; tomcats[0] = new Tomcat(7, "Tommy"); tomcats[1] = new Tomcat(8, "Tomcho"); tomcats[2] = new Tomcat(4, "Tomario"); double averageTomcat = AverageAge(tomcats); Console.WriteLine("Tomcat average age: {0:F2} ", averageTomcat); }
static void Main(string[] args) { Tomcat tom = new Tomcat("Tom", 13); Tomcat pedigree = new Tomcat("Pedigree", 10); Tomcat batman = new Tomcat("Batman the Bulgarian cat", 24); Kitten kitty = new Kitten("Kittycat", 1); Kitten whiskas = new Kitten("Whiskas", 12); Kitten mucka = new Kitten("Mucka the trash cat from Kansas", 18); Frog kermit = new Frog("Kermit the frog", 15, "male"); Frog prince = new Frog("The frog prince", 6, "male"); Frog krastav = new Frog("Pesho the frog", 3, "male"); Dog spike = new Dog("Spike", 25, "male"); Dog goofy = new Dog("Goofy", 14, "male"); Dog courage = new Dog("Courage the cowardly dog", 7, "male"); tom.ProduceSound(); kitty.ProduceSound(); kermit.ProduceSound(); spike.ProduceSound(); List <Animal> teamOne = new List <Animal>(); teamOne.Add(tom); teamOne.Add(pedigree); teamOne.Add(batman); teamOne.Add(kitty); teamOne.Add(mucka); teamOne.Add(whiskas); teamOne.Add(kermit); teamOne.Add(krastav); teamOne.Add(goofy); teamOne.Add(prince); teamOne.Add(spike); teamOne.Add(courage); Console.WriteLine(); // Static method for calculating average age of different kinds of animals AverageAge(teamOne); }
static void Main() { Kitten kitty = new Kitten("kjfl", 1); Tomcat tomas = new Tomcat("fgfv", 2); Dog sharo = new Dog("fvdv", 3, SexEnum.male); Frog squeek = new Frog("vfdv", 1, SexEnum.female); kitty.MakeSomeNoise(); tomas.MakeSomeNoise(); sharo.MakeSomeNoise(); squeek.MakeSomeNoise(); Console.WriteLine(tomas.Gender); Console.WriteLine(kitty.Gender); Animal[] animals = { new Kitten("fgvgfg", 2), new Tomcat("vfvfdv", 4), new Dog("vfdfv", 5,SexEnum.female), new Frog("vfvfv", 2,SexEnum.female), new Kitten("fgvgfg", 6), new Tomcat("vfvfdv", 2), new Dog("vfdfv", 7,SexEnum.female), new Frog("vfvfv", 10,SexEnum.female), new Kitten("fgvgfg", 8), new Tomcat("vfvfdv", 8), new Dog("vfdfv", 9,SexEnum.female), new Frog("vfvfv", 5,SexEnum.female), }; var ordered = animals.GroupBy(x => x.GetType()); Console.WriteLine(); foreach (var animal in ordered) { Console.WriteLine("Average age of {0} is {1:F2}.", animal.Key.Name, animal.Average(x => x.Age)); } }
static void Main() { Dog[] dogs = new Dog[3]; dogs[0] = new Dog(5, "Rex", Sex.male); dogs[1] = new Dog(2, "Lara", Sex.female); dogs[2] = new Dog(14, "Sharo", Sex.male); double averageDog = AverageAge(dogs); Console.WriteLine("Dog average age: {0:F2}",averageDog); Frog[] frogs = new Frog[3]; frogs[0] = new Frog(1, "Kikerica", Sex.female); frogs[1] = new Frog(2, "Juji", Sex.female); frogs[2] = new Frog(3, "Kermit", Sex.male); double averageFrog = AverageAge(frogs); Console.WriteLine("Frog average age: {0:F2}", averageFrog); Cat[] cats = new Cat[3]; cats[0] = new Cat(5, "Pisio", Sex.male); cats[1] = new Cat(12, "Maca", Sex.female); cats[2] = new Cat(11, "Garfield", Sex.male); double averageCat = AverageAge(cats); Console.WriteLine("Cat average age: {0:F2}", averageCat); Kitten[] kittens = new Kitten[3]; kittens[0] = new Kitten(1, "Pisanka"); kittens[1] = new Kitten(2, "Topcho"); kittens[2] = new Kitten(1, "Puhcho"); double averageKitten = AverageAge(kittens); Console.WriteLine("Kitten average age: {0:F2} ", averageKitten); Tomcat[] tomcats = new Tomcat[3]; tomcats[0] = new Tomcat(7, "Tommy"); tomcats[1] = new Tomcat(8, "Tomcho"); tomcats[2] = new Tomcat(4, "Tomario"); double averageTomcat = AverageAge(tomcats); Console.WriteLine("Tomcat average age: {0:F2} ", averageTomcat); }
static void Main() { Kitten kitty = new Kitten("kjfl", 1); Tomcat tomas = new Tomcat("fgfv", 2); Dog sharo = new Dog("fvdv", 3, SexEnum.male); Frog squeek = new Frog("vfdv", 1, SexEnum.female); kitty.MakeSomeNoise(); tomas.MakeSomeNoise(); sharo.MakeSomeNoise(); squeek.MakeSomeNoise(); Console.WriteLine(tomas.Gender); Console.WriteLine(kitty.Gender); Animal[] animals = { new Kitten("fgvgfg",2), new Tomcat("vfvfdv",4), new Dog("vfdfv",5,SexEnum.female), new Frog("vfvfv",2,SexEnum.female), new Kitten("fgvgfg",6), new Tomcat("vfvfdv",2), new Dog("vfdfv",7,SexEnum.female), new Frog("vfvfv",10,SexEnum.female), new Kitten("fgvgfg",8), new Tomcat("vfvfdv",8), new Dog("vfdfv",9,SexEnum.female), new Frog("vfvfv",5,SexEnum.female), }; var ordered = animals.GroupBy(x => x.GetType()); Console.WriteLine(); foreach (var animal in ordered) { Console.WriteLine("Average age of {0} is {1:F2}.",animal.Key.Name, animal.Average(x => x.Age)); } }