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


C# Dog.ToString方法代码示例

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


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

示例1: DogToStringTestWithNonNullWalkDate

        public void DogToStringTestWithNonNullWalkDate()
        {
            Dog dog = new Dog(5, new SimpleDate(9, 4, 1920), "Doggy", new SimpleDate(1, 3, 2000));

            Assert.AreEqual("Dog: 5, 09-04-1920, Doggy, not reserved, €200.00, 01-03-2000", dog.ToString());
        }
开发者ID:grasmanek94,项目名称:SE21,代码行数:6,代码来源:DogTest.cs

示例2: DogToStringTestWithNullWalkDate

        public void DogToStringTestWithNullWalkDate()
        {
            Dog dog = new Dog(5, new SimpleDate(9, 4, 1920), "Doggy", null);

            Assert.AreEqual("Dog: 5, 09-04-1920, Doggy, not reserved, €200.00, unknown", dog.ToString());
        }
开发者ID:grasmanek94,项目名称:SE21,代码行数:6,代码来源:DogTest.cs

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