コード例 #1
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);
        }
コード例 #2
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);
 }