当前位置: 首页>>代码示例>>C#>>正文


C# Dog.ProduceSound方法代码示例

本文整理汇总了C#中Dog.ProduceSound方法的典型用法代码示例。如果您正苦于以下问题:C# Dog.ProduceSound方法的具体用法?C# Dog.ProduceSound怎么用?C# Dog.ProduceSound使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Dog的用法示例。


在下文中一共展示了Dog.ProduceSound方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

    static void Main(string[] args)
    {
        //Create a hierarchy Dog, Frog, Cat, Kitten, Tomcat and define useful
        //constructors and methods. Dogs, frogs and cats are Animals. All animals
        //can produce sound (specified by the ISound interface). Kittens and
        //tomcats are cats. All animals are described by age, name and sex. Kittens
        //can be only female and tomcats can be only male. Each animal produces a specific
        //sound. Create arrays of different kinds of animals and calculate the average
        //age of each kind of animal using a static method (you may use LINQ).

        //Make some animals and test their properties
        Kitten kitty = new Kitten(3, "Kitty");//the sex is aways female
        Console.WriteLine(kitty.Name + "-" + kitty.Age + "-" + kitty.sex);
        kitty.ProduceSound();
        Tomkat tom = new Tomkat(5, "Tom");//the sex is aways male
        Console.WriteLine(tom.Name + "-" + tom.Age + "-" + tom.sex);
        tom.ProduceSound();
        Dog doggy = new Dog(8, "Doggy", Sex.male);
        Console.WriteLine(doggy.Name + "-" + doggy.Age + "-" + doggy.sex);
        doggy.ProduceSound();
        Frog froggy = new Frog(1, "Froggy", Sex.female);
        Console.WriteLine(froggy.Name + "-" + froggy.Age + "-" + froggy.sex);
        froggy.ProduceSound();

        //Make array with diferent animals and calculate the average age for every animal type in the array
        Animal[] animals = {kitty,tom,froggy,doggy,
                                   new Kitten(4,"Keit"),
                                   new Tomkat(5,"Tomas"),
                                   new Dog(11,"Rex",Sex.male),
                                   new Frog(3,"Curmit",Sex.male)};
        CalculateEveryAnimalAverageAge(animals);
    }
开发者ID:Jarolim,项目名称:TelerikAcademy-1,代码行数:32,代码来源:Program.cs

示例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();
        }
开发者ID:emilrr,项目名称:SoftUni-Fundamental-Level,代码行数:32,代码来源:Test.cs

示例3: Main

        static void Main(string[] args)
        {
            try
            {
                Frog Goshko = new Frog("Goshko", 10, "male");
                Frog Dimitrur = new Frog("Dimitur",6, "male");
                Frog Minka = new Frog("Minka", 3, "female");

                Dog Rex = new Dog("Rex", 1, "male");
                Dog Hunter = new Dog("Hunter", 5, "male");
                Dog Blondie = new Dog("Blondie",3,"female");

                Kitten Puxy = new Kitten ("Puxy" , 2);
                Kitten Dazzy = new Kitten("Dazzy",5);
                Kitten Tuffy = new Kitten("Tuffy", 4);

                TomCat Tom = new TomCat("Tom", 4);
                TomCat Djeramaia = new TomCat("Djeramaia", 1);
                TomCat Virgin = new TomCat("Virgin",7);

                IList<Animal> animals = new List<Animal>
                {
                    Goshko,Dimitrur,Minka,Rex,Hunter,Blondie,Puxy,Dazzy,Tuffy,Tom,Djeramaia,Virgin
                };
                Goshko.ProduceSound();
                Rex.ProduceSound();
                Puxy.ProduceSound();
                Tom.ProduceSound();

                double catsAverageAge = animals
                    .Where(animal => animal is Cat)
                    .Average(cat => cat.Age);
                double dogsAverageAge = animals
                                    .Where(animal => animal is Dog)
                                    .Average(dog => dog.Age);

                double frogsAverageAge = animals
                    .Where(animal => animal is Frog)
                    .Average(frog => frog.Age);

                Console.WriteLine("Frogs average age is: {0:F2}", frogsAverageAge);
                Console.WriteLine("Dogs average age is: {0:F2}", dogsAverageAge);
                Console.WriteLine("Cats average age is: {0:F2}", catsAverageAge);

            }
            catch (ArgumentOutOfRangeException ae)
            {
                Console.WriteLine(ae.Message);
            }
            catch (ArgumentNullException ae)
            {
                Console.WriteLine(ae.Message);
            }
            catch (ArgumentException ae)
            {
                Console.WriteLine(ae.Message);
            }
        }
开发者ID:nikolay-dimitrov,项目名称:SoftUniHomeWorks,代码行数:58,代码来源:Program.cs

示例4: 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();
    }
开发者ID:shnogeorgiev,项目名称:Software-University-Courses,代码行数:14,代码来源:AnimalsDemo.cs

示例5: 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();
            }
        }
开发者ID:ivanovcorp,项目名称:SoftwareUniversity,代码行数:50,代码来源:TestCases.cs

示例6: Main

    static void Main()
    {
        Console.ForegroundColor = ConsoleColor.Green;
        Console.WriteLine("Test The Animals...");
        Console.ResetColor();
        Console.WriteLine();

        TomCat tomy = new TomCat("Tom", 3);
        Console.WriteLine("TomCat - " + tomy);
        tomy.ProduceSound();

        Console.WriteLine();

        Dog rex = new Dog("Rex", 5, Gender.Male);
        Console.WriteLine("Dog - " + rex);
        rex.ProduceSound();

        Console.WriteLine();

        Frog flip = new Frog("Flip", 1, Gender.Male);
        Console.WriteLine("Frog - " + flip);
        flip.ProduceSound();

        Console.WriteLine();

        Console.ForegroundColor = ConsoleColor.Green;
        Console.WriteLine("Average Age...");
        Console.ResetColor();
        Console.WriteLine();

        List<Cat> listOfCats = new List<Cat>();
        listOfCats.Add(new Cat("Joney", 5, Gender.Male));
        listOfCats.Add(new Cat("Mike", 1, Gender.Male));
        listOfCats.Add(new Cat("Simi", 5, Gender.Female));

        double catsAverageAge = listOfCats.Average(x => x.Age);
        Console.WriteLine("List Of Cats Average Age: {0}", catsAverageAge);

        List<Dog> listOfDogs = new List<Dog>();
        listOfDogs.Add(new Dog("Sharko", 3, Gender.Female));
        listOfDogs.Add(new Dog("Foxy", 1, Gender.Female));
        listOfDogs.Add(new Dog("Tommy", 5, Gender.Male));

        double dogsAverageAge = listOfDogs.Average(x => x.Age);
        Console.WriteLine("List Of Dogs Average Age: {0}", dogsAverageAge);

        Console.WriteLine();
    }
开发者ID:BorislavIvanov,项目名称:Telerik_Academy,代码行数:48,代码来源:AppTest.cs

示例7: 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));
        }
开发者ID:imurtov,项目名称:InheritanceAndAbstractionHomework,代码行数:43,代码来源:Animals.cs

示例8: 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();
    }
开发者ID:KrumTy,项目名称:TelerikAcademy,代码行数:30,代码来源:AnimalTesting.cs

示例9: 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();
    }
开发者ID:powerslider,项目名称:TelerikAcademyHomeworks,代码行数:74,代码来源:TestAnimals.cs


注:本文中的Dog.ProduceSound方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。