static void Main() { var dogs = new Dogs[] { new Dogs("Rex", 7, Sex.Male), new Dogs("Sharo", 11, Sex.Male), new Dogs("Sara", 15, Sex.Famale) }; var frogs = new Frogs[] { new Frogs("Crazy Frog", 3, Sex.Male), new Frogs("Pesho", 5, Sex.Male), new Frogs("Jabka", 2, Sex.Famale) }; var cats = new Cats[] { new Tomcats("Tom", 5), new Kittens("Kitty", 4), new Cats("Kotan", 6, Sex.Male) }; var averageAgeOfDogs = dogs.Average(d => d.Age); var averageAgeOfFrogs = frogs.Average(f => f.Age); var averageAgeOfCats = cats.Average(c => c.Age); Console.WriteLine("Avarage age of dogs: {0:F1}", averageAgeOfCats); Console.WriteLine("Avarage age of frogs: {0:F1}", averageAgeOfFrogs); Console.WriteLine("Avarage age of cats: {0:F1}", averageAgeOfCats); }
static void Main(string[] args) { Frog[] frogs = new Frog[5]; frogs[0] = new Frog("Kermit", 7, "male"); frogs[1] = new Frog("Kikeriza", 7, "female"); frogs[2] = new Frog("Muholovka", 5, "female"); frogs[3] = new Frog("Purgavka", 3, "female"); frogs[4] = new Frog("Zelenko", 4, "female"); Dogs[] dogs = new Dogs[5]; dogs[0] = new Dogs("Sharo", 9, "male"); dogs[1] = new Dogs("Sharik", 11, "male"); dogs[2] = new Dogs("Murdjo", 7, "male"); dogs[3] = new Dogs("Minka", 10, "female"); dogs[4] = new Dogs("Lili", 8, "female"); Cats[] cats = new Cats[5]; cats[0] = new Kitten("Maca", 11); cats[1] = new Kitten("Puffi", 12); cats[2] = new TomCat("Chocho", 15); cats[3] = new TomCat("James", 10); cats[4] = new TomCat("Blacky", 17); var frogsAverageAge = frogs .Average(frog => frog.Age); var dogsAverageAge = dogs .Average(dog => dog.Age); var catsAverageAge = cats .Average(cat => cat.Age); Console.WriteLine("The average age of the frogs is {0}", frogsAverageAge.ToString()); Console.WriteLine(); Console.WriteLine("The average age of the dogs is {0}", dogsAverageAge.ToString()); Console.WriteLine(); Console.WriteLine("The average age of the cats is {0}", catsAverageAge.ToString()); Console.WriteLine(); }