Skip to content

Instantly share code, notes, and snippets.

@NMZivkovic
Created September 28, 2017 10:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NMZivkovic/5b56d53d4e78cc5fe5d79ead7a764376 to your computer and use it in GitHub Desktop.
Save NMZivkovic/5b56d53d4e78cc5fe5d79ead7a764376 to your computer and use it in GitHub Desktop.
var shapes = new Dictionary<string, object>
{
{ "FirstShape", new Rectangle(1, 1) },
{ "SecondShape", new Circle(6) }
};
foreach(var shape in shapes)
{
if (shape.Value is Rectangle)
{
var height = ((Rectangle)shape.Value).Height;
Console.WriteLine(height);
}
else if (shape.Value is Circle)
{
var height = ((Circle)shape.Value).Radius * 2;
Console.WriteLine(height);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment