Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Delegates_Covariance
- {
- class Program
- {
- public delegate Shape GetShape();
- public static Rectangle GetRectangle()
- {
- return new Rectangle();
- }
- public static Circle GetCircle()
- {
- return new Circle();
- }
- static void Main(string[] args)
- {
- GetShape getCircleMethod = GetCircle;
- GetShape getRectangleMethod = GetRectangle;
- Console.WriteLine(getCircleMethod());
- Console.WriteLine(getRectangleMethod.Invoke());
- }
- }
- public class Shape { }
- public class Rectangle : Shape
- {
- public override string ToString()
- {
- return "I'm Circle";
- }
- }
- public class Circle : Shape
- {
- public override string ToString()
- {
- return "I'm Rectangle";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement