Exemplo n.º 1
0
 static void Show(Animal[] Animal_L)
 {
     foreach (Animal an in Animal_L)
     {
         Console.WriteLine("Animail: " + an.Genus + "   " + " Weight: " + an.Weight);
     }
 }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            int choice;           
            
            Animal[] Animal_L = new Animal[6];

            Animal_L[0] = new Animal("pig", 50);
            Animal_L[1] = new Animal("dog", 20);
            Animal_L[2] = new Animal("cat", 5);
            Animal_L[3] = new Animal("kangaroo", 70);
            Animal_L[4] = new Animal("elephant", 700);
            Animal_L[5] = new Animal("mouse", 1);

            do
            {
                Console.WriteLine(@"                 1. Sort with method ComareTo();
                 2. Sort with SortWeightAscending;
                 3. Sort with SortGenusDescending;
                 4. In class Animals;
                 5. Exit");
                choice = int.Parse(Console.ReadLine());
                switch (choice)
                {
                    case 1:
                        Array.Sort(Animal_L);
                        Show(Animal_L);                                               
                        break;
                    case 2:
                        Array.Sort(Animal_L, Animal.SortWeightAscending());
                        Show(Animal_L);
                        break;
                    case 3:                        
                        Array.Sort(Animal_L, Animal.SortGenusDescending());
                        Show(Animal_L);
                        break;
                    case 4:
                        Animals AnimalsOb = new Animals(Animal_L);
                        
                        foreach (Animal oba in AnimalsOb)
                        {
                            Console.WriteLine(oba);
                        }
                        break;                        
                }
            }while(choice!=5);            
            
        }
Exemplo n.º 3
0
 public Animals(Animal [] array)
 {
     animal = array;
 }