Created
June 18, 2018 20:45
-
-
Save matolg/43ad9b981b828782cd3b1009a6c9aa97 to your computer and use it in GitHub Desktop.
C# double dispatch example
This file contains 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
internal class Program | |
{ | |
public interface IVisitor | |
{ | |
void MethodA(object param); | |
void MethodA(string param); | |
} | |
public class VisitorA : IVisitor | |
{ | |
public void MethodA(object param) | |
{ | |
Console.WriteLine("VisitorA object"); | |
} | |
public void MethodA(string param) | |
{ | |
Console.WriteLine("VisitorA string"); | |
} | |
} | |
public class VisitorB : IVisitor | |
{ | |
public void MethodA(object param) | |
{ | |
Console.WriteLine("VisitorB object"); | |
} | |
public void MethodA(string param) | |
{ | |
Console.WriteLine("VisitorB string"); | |
} | |
} | |
private static void Main() | |
{ | |
IVisitor visitor = new VisitorB(); | |
object param = "123"; | |
visitor.MethodA(param); // VisitorB object | |
Console.ReadKey(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment