Created
July 5, 2015 08:41
-
-
Save faridprogrammer/4340d90592fff835255f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BaseShape | |
{ | |
public virtual void Display() | |
{ | |
Console.WriteLine("Displaying Base Class!"); | |
} | |
} | |
class Circle : BaseShape | |
{ | |
public override void Display() | |
{ | |
Console.WriteLine("Displaying Circle Class!"); | |
} | |
} | |
class Rectangle : BaseShape | |
{ | |
public override void Display() | |
{ | |
Console.WriteLine("Displaying Rectangle Class!"); | |
} | |
} | |
class Result | |
{ | |
public static List<BaseShape> Shapes = new List<BaseShape>(); | |
public static void Main() | |
{ | |
Shapes.Add(new Circle()); | |
Shapes.Add(new Circle()); | |
DisplayShapes_BAD(); | |
} | |
public static void DisplayShapes_BAD(){ | |
foreach(var item in Shapes) | |
{ | |
if(typeof(Circle) == item.GetType()) | |
{ | |
((Circle)item).Display(); | |
} | |
if(typeof(Rectangle) == item.GetType()) | |
{ | |
((Circle)item).Display(); | |
} | |
} | |
} | |
public static void DisplayShapes_GOOD(){ | |
foreach(var item in Shapes) | |
{ | |
item.Display(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment