Is C# a single dispatch or multiple dispatch language?

double dispatch c#
python multiple dispatch
haskell multiple dispatch
single dispatch method
rust multiple dispatch
message dispatch
scala multiple dispatch
dynamic dispatch wikipedia

I'm trying to understand what single and multiple dispatch are, exactly.

I just read this: http://en.wikipedia.org/wiki/Multiple_dispatch

And from that definition is seems to me that C# and VB.Net are multiple-dispatch, even though the choice of which overload to call is made at compile-time.

Am I correct here, or am I missing something? Thanks!


OK, I understood the subtle difference where function overloading is different from multiple-dispatch.

Basically, the difference is whether which method to call is chosen at run-time or compile-time. Now, I know everybody's said this, but without a clear example this sounds VERY obvious, given that C# is statically typed and multiple-dispatch languages (apparently to me, at least) seem to be dynamically typed. Up to now, with just that definition multiple-dispatch and function overloading sounded exactly the same to me.

The case where this makes a real difference is when you have 2 overloads of a method which differ on the type of a parameter, but the 2 types are polymorphic, and you call with a reference declared as the higher type, which has an object of the lower type... (If someone can think of a better way to express this, please feel free to edit this answer)

Example:

int CaptureSpaceShip(IRebelAllianceShip ship) {}
int CaptureSpaceShip(XWing ship) {}

void Main() { 
  IRebelAllianceShip theShip = new XWing();
  CaptureSpaceShip(theShip);
}

XWing obviously implements IRebelAllianceShip. In this case, the first method will be called, whereas if C# implemented multiple-dispatch, the second method would be called.

Sorry about the doc rehash... This seems to me the clearest way to explain this difference, rather than just reading the definitions for each dispatch method.

For a more formal explanation: http://en.wikipedia.org/wiki/Double_dispatch#Double_dispatch_is_more_than_function_overloading

Multiple dispatch, OK, I understood the subtle difference where function overloading is different from multiple-dispatch. Basically, the difference is whether which method to call is   Multiple dispatch or multimethods is a feature of some programming languages in which a function or method can be dynamically dispatched based on the run time (dynamic) type or, in the more general case, some other attribute of more than one of its arguments.


For those that find this article using a search engine, C# 4.0 introduces the dynamic keyword. The code would look like the following.

int CaptureSpaceShip(IRebelAllianceShip ship) {}
int CaptureSpaceShip(XWing ship) {}

void Main() {   
    IRebelAllianceShip theShip = new XWing();  
    CaptureSpaceShip((dynamic)theShip);
}

Double dispatch, Static, Single or Dynamic Dispatch is the ability of an object-oriented to dynamic language and enables C# to support multiple dispatch. For example, single dispatch feels like the natural choice in an object-oriented language where an object "receives" a method/message (I'm thinking of Java, but any language that uses the same receiver.method(args) syntax falls into this category), whereas multiple dispatch feels more natural in e.g. Common Lisp, where none of the arguments to


C# is single dispatch but there are some blog posts which by their title looks like they are trying to emulate multimethods. If I can get one of the articles to load I will update my answer here.

Static/Dynamic Dispatch - ReExplained, Almost all well-known object oriented languages (Java, C#, JavaScript, Python, Ruby, ) have single dispatch: Methods are chosen depending  The alternative to single dispatch is multiple dispatch. More than one object is used to determine which method to call. It’s difficult to write an example of how this could be achieved in C# because the language doesn’t support it. (Few languages do support true multiple dispatch, Common Lisp and Clojure are examples of this).


C# does not support multiple dispatch. The Visitor Design pattern emulates something that could be described as multiple dispatch, even though the Visitor pattern's mainly focus on separate the algorithm from an hierarchy.

Multiple Dispatch: A Fix for the Problems of Single Dispatch , Most OO languages implement dynamic dispatch using Virtual most OO langues like C# (prior to V4) and Java, support only single dispatch  A virtual method (single dispatch) is polymorphic in one dimension (the run-time type of the object the method is attached to). Multimethods (multiple dispatch) are polymorphic in multiple dimensions (the run-time types of the arguments, not just the attached object). Multiple Dispatch in C# 4.0 with dynamic


According to the cited Wikipedia article, multiple dispatch, by definition, is based on the runtime types of the objects involved, so C# and VB.net don't use it, because the decision is made, as you state, at compile-time.

Static and Dynamic Dispatch - Ingeniously Simple, Commonly used object-oriented languages like C++, Java and C# are single dispatch languages and do not support multiple polymorphic arguments in  Almost all well-known object oriented languages (Java, C#, JavaScript, Python, Ruby, ) have single dispatch: Methods are chosen depending on the (single) receiver of a message.


Contemporary Computing: Third International Conference, IC3 2010, , Dynamic Dispatch is every Dispatch with: More than one Used mostly in object oriented languages Java, C#, JS, Python, Ruby can handle single dispatch. C# does support only Static and Single Dispatch, and with the help of dynamic keyword, it supports double/multiple dispatch. Generally speaking, if your program needs double/multiple dispatch, then there might be chances of some application design issues.


[PDF] Multiple Dispatching, Single dispatch is what we usually refer to as "runtime polymorphism" in languages like C++ and Java [1]. We have an object on which we call  The best way to understand multiple dispatch is to first think about single dispatch. Single dispatch is what we usually refer to as "runtime polymorphism" in languages like C++ and Java [1] . We have an object on which we call a method, and the actual method being called at runtime depends on the runtime type of the object.


A polyglot's guide to multiple dispatch, Dynamic dispatch contrasts with static dispatch, in which the implementation of a polymorphic operation is selected at compile time. The purpose of dynamic dispatch is to defer the selection of an appropriate implementation until the run time type of a parameter (or multiple parameters) is known.