本文整理汇总了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);
}
示例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;
}
示例3: loopThroughAnimals
static void loopThroughAnimals(Animal[] AnimalArray)
{
for (int i = 0; i < AnimalArray.Length; i++)
{
AnimalArray[i].SaySomething();
}
}
示例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/");
}
示例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 ();
}
示例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;
}
示例7: QuestionsViewModel
public QuestionsViewModel(Animal animal)
{
AnimalFeature = animal.Feature;
AnimalId = animal.Id;
AnimalName = animal.Name;
Step = 1;
}
示例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();
}
示例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)
);
}
示例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;
}
示例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);
}
}
}
示例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);
}
示例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));
}
示例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();
}
示例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);
}