コード例 #1
0
ファイル: StartUp.cs プロジェクト: kkaraivanov/CCharpAdvanced
        public static void Main()
        {
            var    animals = new List <Animal>();
            string input   = null;

            while ((input = Console.ReadLine()) != "Beast!")
            {
                string typeAnymal = input;
                var    info       = Console.ReadLine()
                                    .Split(' ', StringSplitOptions.RemoveEmptyEntries)
                                    .ToArray();
                Animal animal = null;
                try
                {
                    switch (typeAnymal)
                    {
                    case "":
                        animal = new Animal(info[0], int.Parse(info[1]), info[2]);
                        break;

                    case "Cat":
                        animal = new Cat.Cat(info[0], int.Parse(info[1]), info[2]);
                        break;

                    case "Dog":
                        animal = new Dog.Dog(info[0], int.Parse(info[1]), info[2]);
                        break;

                    case "Frog":
                        animal = new Frog.Frog(info[0], int.Parse(info[1]), info[2]);
                        break;

                    case "Kitten":
                        animals.Add(new Kitten(info[0], int.Parse(info[1]))); break;

                    case "Tomcat":
                        animals.Add(new Tomcat(info[0], int.Parse(info[1]))); break;

                    default:
                        throw new ArgumentException("Invalid input!");
                    }
                }
                catch (ArgumentException ae)
                {
                    Console.WriteLine(ae.Message);
                }


                animals.Add(animal);
            }

            foreach (var animal in animals)
            {
                Console.WriteLine(animal);
            }
        }
コード例 #2
0
        //using the class
        static void Main()
        {
            Cat firstCat = new Cat();       //make a new cat object
            firstCat.Name = "Fischer";      //give a new name to the cat
            firstCat.Miau();                //make the cat miau :>

            Cat anotherCat = new Cat("Stevie", "brown"); //making a new cat object with constructor that has parameters
            anotherCat.Miau();
            Console.WriteLine("Cat {0} is {1}.", anotherCat.Name, anotherCat.Color);
        }
コード例 #3
0
 static void Main(string[] args)
 {
     //creating a new cat object using the parameterless constructor
     Cat.Cat randomCat = new Cat.Cat();
     randomCat.Miau();
     Console.WriteLine("The color of cat {0} is {1}.", randomCat.Name, randomCat.Color);
     //creating a new cat object using the constructor that takes two parameters
     Cat.Cat specificCat = new Cat.Cat("Fischer", "black");
     specificCat.Miau();
     Console.WriteLine("The color of cat {0} is {1}", specificCat.Name, specificCat.Color);
 }
コード例 #4
0
 static void Main(string[] args)
 {
     Cat.Cat myCat = new Cat.Cat();
     myCat.Name = "Alfred";
     Console.WriteLine("The name of my cat is {0}", myCat.Name);
 }
コード例 #5
0
ファイル: Program.cs プロジェクト: Frosne/SShA
 static void Main(string[] args)
 {
     Cat cat = new Cat();
     cat.GetAllProcesses();
 }