Usman Usman - 1 year ago 183
C# Question

Method Signature in C#

What is the Method Signature in the following

int DoSomething(int a, int b);

Return type is a part of signature or not???

Answer Source

Return type is not part of the method signature in C#. Only the method name and its parameters types (but not the parameter names) are part of the signature. You cannot, for example, have these two methods:

int DoSomething(int a, int b);
string DoSomething(int a, int b);

To be clear: Methods cannot be overloaded based on their return type. They must have a unique name, unique parameter types, or pass their arguments differently (e.g. using out or ref).

Edit: To answer your original question, the method signature for your method is:

DoSomething(int, int)

Note that this all applies to normal methods. If you're talking about delegates, then you should see keyboardP's answer. (Short version: return type IS part of the signature for a delegate).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download