static void Main(string[] args) { Dog spotty = new Dog(); spotty.name = "Spotty"; spotty.age = 4; spotty.happiness = 0.8f; spotty.spotCount = 25; spotty.PrintBase(); spotty.Bark(); Console.WriteLine("New happiness: " + spotty.happiness); }
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) { Console.WriteLine(Helper.Multiply(6, 8)); Cat a = new Cat("John", "The cat"); a.Price = Helper.Randomize(); a.Meow(); Dog b = new Dog("Mike", "The dog"); b.Price = Helper.Randomize(); b.Bark(); }
static void Main(string[] args) { Dog objDog = new Dog(); objDog.Bark(); objDog.Eat(); Console.WriteLine("//////////////////////////"); Cat objCat = new Cat(); objCat.Meow(); objCat.Eat(); Console.ReadLine(); }
static void Main(string[] args) { Puppy puppy = new Puppy();//Multiple Inheritance puppy.Eat(); puppy.Bark(); puppy.Weep(); Dog dog = new Dog();//Single Inheritance dog.Bark(); dog.Eat(); Cat cat = new Cat();//Heirarchial Inheritance cat.Meow(); cat.Eat(); }
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(); }
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(); }
static void Main(string[] args) { //Console.WriteLine("Single Inheritance"); /*Console.WriteLine("Multiple Inheritance"); * Puppy puppy = new Puppy(); * puppy.Eat(); * puppy.Bark(); * puppy.Weep();*/ Console.WriteLine("Hierarchial Inheritance"); Dog dog = new Dog(); dog.Eat(); dog.Bark(); Cat cat = new Cat(); cat.Eat(); cat.Meow(); }
static void Main(string[] args) { Dog myDog = new Dog(); myDog.Eat(); myDog.Bark(); Console.WriteLine(); Puppy myPyppy = new Puppy(); myPyppy.Eat(); myPyppy.Bark(); myPyppy.Weep(); Console.WriteLine(); Cat myCat = new Cat(); myCat.Eat(); myCat.Meow(); }
static void Main(string[] args) { Dog fido = new Dog(); Puppy puppy = new Puppy(); Cat cat = new Cat(); Console.WriteLine("Fido:"); fido.Eat(); fido.Bark(); Console.WriteLine(); Console.WriteLine("Puppy:"); puppy.Eat(); puppy.Bark(); puppy.Weep(); Console.WriteLine(); Console.WriteLine("Cat:"); cat.Eat(); cat.Meow(); }
static void Main(string[] args) { Animal animal = new Animal("green"); animal.Eat("food"); PrintColour(animal); Dog dog = new Dog("blue", "bichon"); dog.Eat("bones"); dog.Bark(); PrintColour(dog); Snake snake = new Snake("yellow", false); snake.Bite(); PrintColour(snake); HuntingDog huntingDog = new HuntingDog("pink", "staff", 120); huntingDog.Hunt(); PrintColour(snake); Animal[] animals = new Animal[] { animal, dog, snake, huntingDog }; Console.WriteLine("Iterating through the animals array\n"); foreach (var a in animals) { a.Eat("food for animals"); } Console.ReadLine(); }
static void Main(string[] args) { Animal animal = new Animal(); Console.WriteLine(animal.Eat()); Dog dog = new Dog(); Console.WriteLine(dog.Eat()); Console.WriteLine(dog.Bark()); Cat cat = new Cat(); Console.WriteLine(cat.Eat()); Console.WriteLine(cat.Meow()); Puppy puppy = new Puppy(); Console.WriteLine(puppy.Eat()); Console.WriteLine(puppy.Bark()); Console.WriteLine(puppy.Weep()); }
static void Main(string[] args) { // can be done because is not abstract!!! Mammal m = new Mammal("Rex"); Dog dog = new Dog("Jamie"); dog.Bark(); // we cannot access protected members // dog._name = "Joro"; Cat cat = new Cat("Misha"); cat.Meaw(); Human human = new Human("Stanislava"); human.Speak("Hello"); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); }
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(); }