virtual intended for separate sending. If you need double dispatch, you can do it in C #:
var objs = new object[] { new Class1(), new Class2() }; foreach (var item in objs) { Method((dynamic)item); }
This will make the compiler interpret the call to your method in a completely different way. It will call the so-called call site, which will determine at runtime which method to call. This is also called late binding.
In this particular example, you still get a separate dispatch, but that would be a double dispatch if Method were virtual.
This is very convenient for quick implementation of the visitor template, but keep in mind that this will be slower than classic manual double sending. This way you can use the good old way in performance-sensitive code.
source share