Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- public interface IDog
- {
- string Name {get;}
- string Breed {get;}
- }
- public class Dog: IDog
- {
- public string Name {get;}
- public string Breed {get;}
- public Dog(string name, string breed)
- {
- this.Name = name;
- this.Breed = breed;
- }
- public Dog(string breed)
- :this(null,breed)
- {
- this.Breed = breed;
- }
- public Dog()
- {
- }
- public override string ToString()
- {
- string s;
- if(this.Breed != null && this.Name != null)
- {
- s = string.Format("The {0} dog {1} said BARK!",this.Breed,this.Name);
- }
- else if(this.Name == null && this.Breed != null)
- {
- s = string.Format("The unnamed {0} dog said BARK!",this.Breed);
- }
- else
- {
- s = null;
- }
- return s;
- }
- }
- public class Program
- {
- public static void Main()
- {
- Dog sharo = new Dog("Sharo","corgi");
- Dog rex = new Dog("Rex","poodle");
- Dog unnamed = new Dog(null,"hound");
- Dog[] dogs = new Dog[]{sharo, rex,unnamed};
- foreach(var dog in dogs)
- {
- Console.WriteLine(dog);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement