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


C# Dog类代码示例

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


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

示例1: ExecuteInsertUnitCommand

 protected virtual void ExecuteInsertUnitCommand(string[] commandWords)
 {
     switch (commandWords[1])
     {
         case "Dog":
             var dog = new Dog(commandWords[2]);
             this.InsertUnit(dog);
             break;
         case "Human":
             var human = new Human(commandWords[2]);
             this.InsertUnit(human);
             break;
         case "Tank":
             var tank = new Tank(commandWords[2]);
             this.InsertUnit(tank);
             break;
         case "Marine":
             var marine = new Marine(commandWords[2]);
             this.InsertUnit(marine);
             break;
         case "Parasite":
             var parasite = new Parasite(commandWords[2]);
             this.InsertUnit(parasite);
             break;
         case "Queen":
             var queen = new Queen(commandWords[2]);
             this.InsertUnit(queen);
             break;
         default:
             break;
     }
 }
开发者ID:tima-t,项目名称:Telerik-Academy,代码行数:32,代码来源:HoldingPen.cs

示例2: GetField

        public void GetField()
        {
            var getter = _ageField.GetGetter();
              var dog = new Dog();

              Assert.Equal(getter(dog), dog.Age);
        }
开发者ID:leloulight,项目名称:magicgrove,代码行数:7,代码来源:ActivationFacts.cs

示例3: Main

        public static void Main()
        {
            var animals = new List<Animal>();

            var kitten = new Kitten("Kitty", 2);

            SayAngAddToList(kitten, animals);

            var tomcat = new Tomcat("Tom", 1);

            SayAngAddToList(tomcat, animals);

            var frog = new Frog("Froggy", 5, Sex.Male);

            SayAngAddToList(frog, animals);

            var dog = new Dog("Sharo", 4, Sex.Male);

            SayAngAddToList(dog, animals);

            var anotherDog = new Dog("Lassy", 7, Sex.Female);

            SayAngAddToList(anotherDog, animals);

            Console.WriteLine("The average age of all animal is {0}", animals.Average(x => x.Age));
        }
开发者ID:GAlex7,项目名称:TA,代码行数:26,代码来源:AnimalCheck.cs

示例4: Main

        static void Main(string[] args)
        {
            Cat mimi = new Cat("mimi");
            mimi.SHOUTCOUNT = 4;
            mimi.shout();
            Console.WriteLine();

            Cat coco = new Cat("coco");
            coco.SHOUTCOUNT = 2;
            coco.shout();
            Console.WriteLine();

            Dog wangcai = new Dog("wangcai");
            wangcai.SHOUTCOUNT = 8;
            wangcai.shout();
            Console.WriteLine();

            Cow moumou = new Cow("moumou");
            moumou.SHOUTCOUNT = 3;
            moumou.shout();
            Console.WriteLine();

            Sheep miemie = new Sheep("miemie");
            miemie.SHOUTCOUNT = 5;
            miemie.shout();
            Console.WriteLine();

            coco.CatchAnimal();
            wangcai.CatchAnimal();
            Console.ReadLine();
        }
开发者ID:biousco,项目名称:DataBaseLearn,代码行数:31,代码来源:Test.cs

示例5: Person

 public Person(string name, int age, string dogName)
 {
     Name = name;
     Age = age;
     Pet = new Dog(dogName);
     action += (val) => val * val;
 }
开发者ID:buunguyen,项目名称:bike,代码行数:7,代码来源:Person.cs

示例6: 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

示例7: Main

    static void Main()
    {
        Console.Write("Enter first dog's name: ");
        string dogName = Console.ReadLine();
        Console.Write("Enter first dog's breed: ");
        string dogBreed = Console.ReadLine();
        // Use the Dog CONSTRUCTOR to assign name and breed
        Dog firstDog = new Dog(dogName, dogBreed);

        // Create a new dog using the parameterless constructor
        Dog secondDog = new Dog();
        // Use PROPERTIES to set name and breed
        Console.Write("Enter second dog's name: ");
        secondDog.Name = Console.ReadLine();
        Console.Write("Enter second dog's breed: ");
        secondDog.Breed = Console.ReadLine();

        // Create a Dog with no name and breed
        Dog thirdDog = new Dog();

        // Save the dogs in an array
        Dog[] dogs = new Dog[] { firstDog, secondDog, thirdDog };
        // Ask each of the dogs to bark
        foreach(Dog dog in dogs)
        {
            dog.SayBau();
        }
    }
开发者ID:EBojilova,项目名称:CSharp-OOP-June-2015,代码行数:28,代码来源:DogMeeting.cs

示例8: Main

 static void Main()
 {
     Dog D = new Dog();
     D.Sound();
     Cat C = new Cat();
     C.Sound();
 }
开发者ID:gawallsibya,项目名称:BIT_MFC-CShap-DotNet,代码行数:7,代码来源:Client.cs

示例9: 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

示例10: Performance

        public void Performance()
        {
            var getter = _ageField.GetGetter();
              var setter = _ageField.GetSetter();

              var dog1 = new Dog();
              var dog2 = new Dog();

              var iterations = 100000;

              var stopWatch = new Stopwatch();
              stopWatch.Start();

              for (var i = 0; i < iterations; i++)
              {
            setter(dog2, getter(dog1));
              }

              stopWatch.Stop();

              Console.WriteLine("Using delegates: {0}.", stopWatch.Elapsed.TotalMilliseconds);

              stopWatch.Reset();
              stopWatch.Start();

              for (var i = 0; i < iterations; i++)
              {
            _ageField.SetValue(dog2, _ageField.GetValue(dog1));
              }

              Console.WriteLine("Using reflection: {0}.", stopWatch.Elapsed.TotalMilliseconds);
        }
开发者ID:leloulight,项目名称:magicgrove,代码行数:32,代码来源:ActivationFacts.cs

示例11: Collect

 public void Collect(Dog winningDog)
 {
     Cash += MyBet.PayOut(winningDog);
     MyLabel.Text = Name + "'s bet: ";
     fHasPlacedBet = false;
     MyBet = new Bet(); // todo same question as line 28
 }
开发者ID:pietroiusti,项目名称:HFCS,代码行数:7,代码来源:Bettor.cs

示例12: Main

        static void Main(string[] args)
        {
            int? x = null;
            Dog? d = new Dog(); //идентично Nullable<Dog> y = null;
            Nullable<Dog> y = null;
            Console.WriteLine(d.HasValue);  //true если d!=null

            int z = x ?? 30;    //если х null z=30 иначе z=х
            Console.WriteLine(z);
            x = 100;
            z = x ?? 30;
            Console.WriteLine(z);

            //расширение класса строк
            Console.WriteLine("^^^^^^^^^^^^");
            string str = "Vasya";
            Console.WriteLine(str.Double());
            Console.WriteLine(StringExtention.Double(str));

            Console.WriteLine("^^^^^^^^^^^^");
            Console.WriteLine(str.AddStr("Olga"));
            Console.WriteLine(StringExtention.AddStr(str,"Katya",false));

            Console.WriteLine("^^^^^^^^^^^^");
            Human man = new Human { Name = "Gorge" };
            man.Show();
            man.Show("is good man");

            HumanExtention.Show(man);

            Console.ReadKey();
        }
开发者ID:CAHbl4,项目名称:csharp,代码行数:32,代码来源:Program.cs

示例13: Can_index_be_rebuilt

        public void Can_index_be_rebuilt()
        {
            //Arrange
            var dog1 = new Dog { Breed = "Breed A", Name = "Tony", Age = 1 };
            var dog2 = new Dog { Breed = "Breed A", Name = "Andrew", Age = 2 };
            var dog3 = new Dog { Breed = "Breed A", Name = "John", Age = 3 };

            var sut = CacheFactory.CreateFor<Dog>()
               .WithSortedIndex(dog => dog.Breed, dog => dog.Age).Ascending()
               .BuildUp(new[] { dog1, dog2, dog3 });

            //Act
            dog3.Breed = "Changed Breed";
            dog3.Age = 1;

            sut.RebuildIndexes();

            var rebuiltState = sut.Index(dog => dog.Breed).Get("Breed A").ToArray();

            //Assert
            rebuiltState
                .Should()
                .BeEquivalentTo(dog1, dog2)
                .And
                .BeInAscendingOrder(dog => dog.Age);
        }
开发者ID:damian-krychowski,项目名称:simple-cache,代码行数:26,代码来源:SortedIndexTests.cs

示例14: computeMatchScore

        //This method computes a match score between 2 dog instances, a lower score is a better match.
        private int computeMatchScore(Dog UserDog, Dog DatabaseDog)
        {
            int score = INITIAL_MATCH_SCORE;

            //if the dog is no good with children, do not check any further and return a high score.
            if((UserDog.GoodWithChildren == true) && (DatabaseDog.GoodWithChildren == false))
            {
                return No_MATCH;
            }

            //if the dog drools, do not check any further and return a high score.
            if((UserDog.Drools == true) && (DatabaseDog.Drools == true))
            {
                return No_MATCH;
            }

            //For-each other property work out the numeric difference between the properties of the dogs and add this difference to the over all score. If the properties
            //match the difference will be 0 eg 2 - 2 = 0. If the user picks low for a property and the comparing dogs property value is high the difference
            //between these two values will be 1 - 3 = -2 this value is then converted to a positive number and added to the score. No preference value is 0.
            score += Math.Abs((int)UserDog.ActivityLevel - (int)DatabaseDog.ActivityLevel);

            score += Math.Abs((int)UserDog.SheddingLevel - (int)DatabaseDog.SheddingLevel);

            score += Math.Abs((int)UserDog.IntelligenceLevel - (int)DatabaseDog.IntelligenceLevel);

            score += Math.Abs((int)UserDog.Coatlength - (int)DatabaseDog.Coatlength);

            score += Math.Abs((int)UserDog.Size - (int)DatabaseDog.Size);

            return score;
        }
开发者ID:hornoo,项目名称:IN710hornerb1,代码行数:32,代码来源:DogSelectorController.cs

示例15: Main

    static void Main(string[] args)
    {
        Dog Pesho = new Dog();
        Dog sharo = new Dog("Sharo","Ovchar");

        sharo.Bark();
    }
开发者ID:AlexanderDimitrov,项目名称:OOP,代码行数:7,代码来源:Program.cs


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