Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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