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


C# Animal类代码示例

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


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

示例1: CalculateEveryAnimalAverageAge

    private static void CalculateEveryAnimalAverageAge(Animal[] animals)
    {
        int frogYears = 0, frogs = 0;
        int tomcatYears = 0, tomcats = 0;
        int kittenYears = 0, kittens = 0;
        int dogYears = 0, dogs = 0;

        foreach (Animal animal in animals)
        {
            switch (animal.GetType().ToString())
            {
                case "Kitten": kittenYears += animal.Age;
                    kittens++;
                    break;
                case "Frog": frogYears += animal.Age;
                    frogs++;
                    break;
                case "Tomkat": tomcatYears += animal.Age;
                    tomcats++;
                    break;
                case "Dog": dogYears += animal.Age;
                    dogs++;
                    break;
                default:
                    break;
            }
        }

        Console.WriteLine("Dogs average age is {0}", (decimal)dogYears / dogs);
        Console.WriteLine("Kittens average age is {0}", (decimal)kittenYears / kittens);
        Console.WriteLine("Tomcats average age is {0}", (decimal)tomcatYears / tomcats);
        Console.WriteLine("Frogs average age is {0}", (decimal)frogYears / frogs);
    }
开发者ID:Jarolim,项目名称:TelerikAcademy-1,代码行数:33,代码来源:Program.cs

示例2: removeItem

        /// <summary>
        /// Remove item from cart
        /// </summary>
        /// <param name="animal">Item to remove</param>
        public void removeItem(Animal animal)
        {
            items.Remove(animal);

            // UPDATE cartTotal
            cartTotal -= animal.price;
        }
开发者ID:Bryanoh,项目名称:CSHARP-DOTNET,代码行数:11,代码来源:Cart.cs

示例3: loopThroughAnimals

 static void loopThroughAnimals(Animal[] AnimalArray)
 {
     for (int i = 0; i < AnimalArray.Length; i++)
     {
         AnimalArray[i].SaySomething();
     }
 }
开发者ID:John078,项目名称:INFDEV02-1_0907498,代码行数:7,代码来源:Program.cs

示例4: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["AnimalID"] != null)
        {
            if (Session["User"] == null)
            {
                Response.Redirect("~/Account/Login?ReturnUrl=Animal/Animal?AnimalID=" + Request.QueryString["AnimalID"].ToString());
            }

            WebsiteUser Op = (WebsiteUser)Session["User"];

            if (Animal.Exists(Convert.ToUInt32(Request.QueryString["AnimalID"].ToString())))
            {
                Page.Title = "Animal - " + Animal.Id2Name(Convert.ToUInt32(Request.QueryString["AnimalID"].ToString()));
                Animal Animalito = new Animal(Convert.ToUInt32(Request.QueryString["AnimalID"].ToString()));
                if (Animal.isValidOwner(Op, Convert.ToUInt32(Request.QueryString["AnimalID"].ToString())))
                {
                    if (!IsPostBack)
                        LoadFields(Animalito);
                }
                else
                    Response.Redirect("~/Animal/");
            }
            else
            {
                Response.Redirect("~/Animal/");
            }
        }
        else
            Response.Redirect("~/Animal/");
    }
开发者ID:luiseduardohdbackup,项目名称:MobilVet,代码行数:31,代码来源:Animal.aspx.cs

示例5: CreateAnimal

    public void CreateAnimal(string s, int ag)
    {
        Animal a = new Animal ();
        a.name = s;

        int ran = Random.Range (0, 2);
        if (ran == 0) {
            a.gender = GenderTypes.Male;
        } else {
            a.gender = GenderTypes.Female;
        }

        a.age = ag;

        float ragd = Random.Range(1.2f,3f);
        ragd = Mathf.Pow(ragd,3f);

        a.ageOfDeath = (int)ragd;

        if (a.ageOfDeath < a.age) {
            a.ageOfDeath += a.age;
        }

        Debug.Log ("AGE "+ag+" "+a.ageOfDeath);

        animals.Add (a);

        FamilyResources.instance.UpdateAmountOfAnimals ();
    }
开发者ID:Bjeck,项目名称:Taokoyn-Nomad,代码行数:29,代码来源:Animals.cs

示例6: addItem

        /// <summary>
        /// Add item to cart
        /// </summary>
        /// <param name="animal">Item to add</param>
        public void addItem(Animal animal)
        {
            items.Add(animal);

            // UPDATE cartTotal
            cartTotal += animal.price;
        }
开发者ID:Bryanoh,项目名称:CSHARP-DOTNET,代码行数:11,代码来源:Cart.cs

示例7: QuestionsViewModel

 public QuestionsViewModel(Animal animal)
 {
     AnimalFeature = animal.Feature;
     AnimalId = animal.Id;
     AnimalName = animal.Name;
     Step = 1;
 }
开发者ID:RitaBu,项目名称:animal-game,代码行数:7,代码来源:QuestionsViewModel.cs

示例8: Main

        static void Main(string[] args)
        {
            // 10) Create an arary of Animal objects and object of Animals
            // print animals with foreach operator for object of Animals
            Animal[] animal = new Animal[5];
            animal[0] = new Animal("Dog", 30);
            animal[1] = new Animal("Cat", 7);
            animal[2] = new Animal("Cow", 1200);
            animal[3] = new Animal("Tiger", 500);
            animal[4] = new Animal("Lion", 600);

            Animals zoo = new Animals(animal);
            Console.WriteLine("Animals:");
            print(zoo);

            // 11) Invoke 3 types of sorting
            // and print results with foreach operator for array of Animal objects
            Console.WriteLine(new string('*', 30));
            Console.WriteLine("Sorting by genus:" );
            Array.Sort(animal);
            print(zoo);

            Console.WriteLine(new string('*', 30));
            Console.WriteLine("Sorting by weigh ascending:");
            Array.Sort(animal, Animal.SortWeightAscending);
            print(zoo);

            Console.WriteLine(new string('*', 30));
            Console.WriteLine("Sorting by genus descending:");
            Array.Sort(animal, Animal.SortGenusDescending);
            print(zoo);

            Console.ReadLine();
        }
开发者ID:TaranenkoVP,项目名称:BA-labs-,代码行数:34,代码来源:Program.cs

示例9: GetAverageAge

 public static IDictionary<string, decimal> GetAverageAge(Animal[] animals)
 {
     return animals.GroupBy(x => x.GetType()).ToDictionary(
         x => x.Key.Name,
         x => x.Average(y => y.Age)
     );
 }
开发者ID:RuParusheva,项目名称:TelerikAcademy,代码行数:7,代码来源:Animal.cs

示例10: CheckMatch

    public bool CheckMatch(Animal animal)
    {
        int x = animal.Index; // animal's row
        int y = Block[x].IndexOf(animal.gameObject); // animal's column

        for (int i = 0; i < 8; i++)
        {
            Animal first = ((GameObject)Block[x][i]).GetComponent<Animal>();
            Animal second = ((GameObject)Block[x][i + 1]).GetComponent<Animal>();
            Animal third = ((GameObject)Block[x][i + 2]).GetComponent<Animal>();

            if (first.ClipName == second.ClipName && second.ClipName == third.ClipName)
            {
                if (first == animal || second == animal || third == animal) return true;
            }
        }

        for (int i = 0; i < 4; i++)
        {
            Animal first = ((GameObject)Block[i][y]).GetComponent<Animal>();
            Animal second = ((GameObject)Block[i + 1][y]).GetComponent<Animal>();
            Animal third = ((GameObject)Block[i + 2][y]).GetComponent<Animal>();

            if (first.ClipName == second.ClipName && second.ClipName == third.ClipName)
            {
                if (first == animal || second == animal || third == animal) return true;
            }
        }
        return false;
    }
开发者ID:nghia89hoang,项目名称:How-To-Make-3Match-Puzzle-Unity,代码行数:30,代码来源:PuzzleManager.cs

示例11: can_get_animals_using_explicit_relationship_between_animal_and_enclosure

        public void can_get_animals_using_explicit_relationship_between_animal_and_enclosure()
        {
            using (var sandbox = new LocalDb())
            {
                Runner.MigrateToLatest(sandbox.ConnectionString);

                using (var context = new ZooDbContext(sandbox.ConnectionString))
                {
                    var enclosure = new Enclosure() { Id = 1, Name = "Kenya", Location = "Africa", Environment = "Sahara" };
                    var animal = new Animal() { Name = "Nala", Species = "Lion", EnclosureId = 1 };

                    context.Animals.Add(animal);
                    context.Enclosures.Add(enclosure);
                    context.SaveChanges();

                    var controller = new HomeController() { Database = context };

                    var result = controller.Index() as ViewResult;
                    var model = result == null ? new IndexViewModel() : result.Model as IndexViewModel;

                    Assert.Equal(1, model.Animals.Count());
                    Assert.Equal("Nala", model.Animals.First().AnimalName);
                }
            }
        }
开发者ID:chuongnt13,项目名称:fluentmigrator-zoo,代码行数:25,代码来源:IntegrationTests.cs

示例12: Property2

 public static void Property2()
 {
     var duck = new Animal() { Name = "Donal" };
     var property = duck.GetType().GetProperty("Name");
     var value = (string)property.GetValue(duck,null);
     Console.WriteLine("Valor property WTIF:" + value);
 }
开发者ID:benicioavila,项目名称:70-483,代码行数:7,代码来源:Program.cs

示例13: Main

    static void Main()
    {
        Animal[] animals = new Animal[] {
            new Tomcat("Pesho", 2),
            new Kitten("Mimi", 4),
            new Dog("Sharo", 3, Sex.Male),
            new Frog("Kermit", 5, Sex.Male)
        };

        Cat[] cats = new Cat[]
        {
            new Kitten("Mimi", 2),
            new Tomcat("Gosho", 6)
        };

        Console.WriteLine("# Animals");
        foreach (Animal animal in animals)
            Console.WriteLine(animal);

        Console.WriteLine("# Produce sound");
        foreach (ISound animal in animals)
            Console.WriteLine(animal.ProduceSound());

        Console.WriteLine("# Average");
        Console.WriteLine(animals.Average(animal => animal.Age));
        Console.WriteLine(cats.Average(cat => cat.Age));
    }
开发者ID:dgrigorov,项目名称:TelerikAcademy-1,代码行数:27,代码来源:Program.cs

示例14: Main

        static void Main(string[] args)
        {
            WriteHeader("Jedan objekat, klasika");

            var myCat = new Animal("Garfield");
            myCat.Walk("Cat");
            myCat.Talk("Cat");


            WriteHeader("Više objekata");

            var animals = new List<KeyValuePair<string, Animal>>
                              {
                                  new KeyValuePair<string, Animal>("Cat", new Animal("Garfield")),
                                  new KeyValuePair<string, Animal>("Dog", new Animal("Locko")),
                                  new KeyValuePair<string, Animal>("Dog", new Animal("Pajko"))
                              };

            foreach (var animal in animals)
            {
                animal.Value.Walk(animal.Key);
                animal.Value.Talk(animal.Key);
            }

            Console.Read();
        }
开发者ID:bramom,项目名称:Bug.RS,代码行数:26,代码来源:Program.cs

示例15: Main

        static void Main(string[] args)
        {
            Animal[] animals = new Animal[8]
            {
                new Dog("Sharo", 12, Gender.Male),
                new Frog("Froggy", 1, Gender.Female),
                new Kitten("Kitty", 3),
                new Kitten("Katya", 4),
                new Tomcat("Gosho", 5),
                new Tomcat("Assen", 2),
                new Frog("Hopper", 2, Gender.Female),
                new Dog("Murdzho", 17, Gender.Male),
            };

            var dogsAverageAge = animals.Where(x => x is Dog).Average(x => x.Age);
            Console.WriteLine("The average age of all dogs is: {0}", dogsAverageAge);

            var frogsAverageAge = animals.Where(x => x is Frog).Average(x => x.Age);
            Console.WriteLine("The average age of all frogs is: {0}", frogsAverageAge);

            var kittensAverageAge = animals.Where(x => x is Kitten).Average(x => x.Age);
            Console.WriteLine("The average age of all kittens is: {0}", kittensAverageAge);

            var tomcatsAverageAge = animals.Where(x => x is Tomcat).Average(x => x.Age);
            Console.WriteLine("The average age of all tomcats is: {0}", tomcatsAverageAge);
        }
开发者ID:ivailojordanov,项目名称:Fundamental-Level,代码行数:26,代码来源:AnimalsMain.cs


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