示例#1
0
        static void GetShape(IRoundeable aRoundable)
        {
            Console.WriteLine($"Are you circle? {(aRoundable is Elipse)}");
            Console.WriteLine($"Are you eplise? {(aRoundable is Circle)}");

            Circle c2 = aRoundable as Circle; // returns null when its not the same type

            if (c2 != null)
            {
                Console.WriteLine(c2.Radius);
            }

            if (aRoundable is Circle)
            {
                Console.WriteLine("Got a circle");
                Circle c1 = aRoundable as Circle;
                Console.WriteLine(c1.Radius);
            }
            else if (aRoundable is Elipse)
            {
                Console.WriteLine("Got a elipse!");
            }
        }
示例#2
0
 static void DrawRoundShapes(IRoundeable shape)
 {
     shape.DrawRoundShape();
 }