示例#1
0
        static void Main(string[] args)
        {
            // Creating instances of all animals to see what constructors will be called
            // All animals have access to methods from Animal
            Animal dambo = new Animal()
            {
                Name = "Dambo", Id = 5, Type = "Elephant"
            };

            dambo.PrintInfo();
            dambo.Eat();
            Console.WriteLine("----------------------------------------------------------");
            Dog spark = new Dog()
            {
                Name = "Spark", Id = 2, Type = "Dog", Race = "Labrador"
            };

            spark.PrintInfo();
            spark.Eat();
            spark.Bark();
            Console.WriteLine("----------------------------------------------------------");
            Cat garfield = new Cat()
            {
                Name = "Garfield", Id = 3, Lazyness = "Very"
            };                                                                         // We don't tell the type here because the constructor will set it

            garfield.PrintInfo();
            garfield.Eat();
            garfield.Meow();
            Console.ReadLine();
        }
示例#2
0
        static void Main(string[] args)
        {
            Dog jango = new Dog()
            {
                Id   = 1,
                Name = "Jango",
                //Type = "Dog",
                Race = "Poodle"
            };

            jango.PrintInfo();
            jango.Eat();

            jango.Bark();

            Console.WriteLine();

            Animal dambo = new Animal()
            {
                Id   = 2,
                Name = "Dambo",
                Type = AnimalTypes.Other
            };

            dambo.PrintInfo();
            dambo.Eat();

            Console.WriteLine();

            Cat kitty = new Cat()
            {
                Id   = 3,
                Name = "Kitty",
                //Type = "Cat",
                Laziness = "Very lazy"
            };

            kitty.PrintInfo();
            kitty.Meow();
            kitty.Eat();

            Console.WriteLine();

            WeekDays tuesday = WeekDays.Tuesday;

            Console.WriteLine(tuesday);
            Console.WriteLine(tuesday.ToString() == "Tuesday");
            Console.WriteLine(tuesday == (WeekDays)2);

            Console.WriteLine();

            Mouse mouse = new Mouse();
        }
        static void Main(string[] args)
        {
            Animal dambo = new Animal()
            {
                Id   = 2,
                Name = "Dambo",
                Type = AnimalTypes.Other
            };

            dambo.PrintInfo();
            dambo.Eat();
            Dog jango = new Dog()
            {
                Id   = 1,
                Name = "Jango",
                Race = "Pudle"
            };

            // methods that dog inherits from animal
            jango.PrintInfo();
            jango.Eat();
            // method that is specific only for dog
            jango.Bark();

            Cat kitty = new Cat()
            {
                Id       = 3,
                Name     = "Kitty",
                Lazyness = "Very"
            };

            Console.WriteLine("-------------------------------------------------------------");
            //kitty.Meow();
            //kitty.PrintInfo();
            //kitty.Eat();
            Console.WriteLine(kitty.Type);

            Mouse mouse = new Mouse();

            // casting
            //int castedValue = (int)WeekDays.Tuesday;
            //int number = 5;
            //WeekDays tuesday = (WeekDays)number;
            //Console.WriteLine(tuesday);
            Console.ReadLine();
        }
示例#4
0
        static void Main(string[] args)
        {
            Animal dumbo = new Animal()
            {
                Id   = 1,
                Name = "Dumbo",
                Type = "elephant",
                // IsHappy = true - we can't access this here
            };

            dumbo.PrintInfo();
            dumbo.Eat();
            Console.WriteLine("-----------------------------------------");

            Dog baron = new Dog()
            {
                Id   = 2,
                Type = "dog",
                Name = "Barron",
                Race = "German sheppard"
            };

            baron.PrintInfo();
            baron.Eat();
            baron.Bark();
            baron.IsDogHappy();
            Console.WriteLine("-----------------------------------------");

            Cat garfield = new Cat()
            {
                Id       = 3,
                Name     = "Garfield",
                Laziness = "very much"
            };

            // we don't tell the type here
            garfield.PrintInfo();
            garfield.Eat();
            garfield.Meow();
            Console.WriteLine("-----------------------------------------");

            Console.ReadLine();
        }
示例#5
0
        static void Main(string[] args)
        {
            Console.WriteLine("Inheritance in C#!");
            Console.WriteLine("------------------------------");

            Animal dumbo = new Animal()
            {
                Id   = 1,
                Name = "Dumbo",
                Type = "elephant"
                       // IsHappy = true - we can't access it here it's protected
            };

            dumbo.PrintInfo();
            dumbo.Eat();
            Console.WriteLine("------------------------------");
            Dog vele = new Dog()
            {
                Id    = 2,
                Type  = "dog",
                Name  = "Vele",
                Breed = "dzukela"
            };

            vele.PrintInfo();
            vele.Eat();
            vele.Bark();
            vele.IsDogHappy();
            Console.WriteLine("------------------------------");
            Cat garfield = new Cat()
            {
                Id       = 3,
                Name     = "Garfield",
                Laziness = "very much"
            };

            // we don't tell the type
            garfield.PrintInfo();
            garfield.Eat();
            // another overload is
            garfield.Eat("fish");
            garfield.Meow();
            Console.WriteLine("------------------------------");

            #region Enums
            // Enumerators
            Console.WriteLine(DayOfWeek.Tuesday);
            DiscountDay dayOne = new DiscountDay()
            {
                Discount = 10,
                Day      = DayOfWeek.Monday
            };
            Console.WriteLine($"On {dayOne.Day} you would have {dayOne.Discount}% discount");
            int dayOneInteger = (int)dayOne.Day;
            Console.WriteLine(dayOneInteger);

            // casting into integer
            DateTime today = DateTime.Now;
            // casting into integer
            int dayWeekToday = (int)today.DayOfWeek;
            Console.WriteLine(dayWeekToday);
            #endregion
            Console.ReadLine();
        }