A
signature makes a method look unique to the compiler.
The
method
name and the
type
and order of parameters all contribute to the uniqueness of signatures.
Methods, constructors, indexers, and operators
are characterized by their signatures.
Signatures enable the
overloading
mechanism of members in
classes, structs, and
interfaces.
A
method signature
consists of the name of the method and
the type and kind, such as value or reference.
A method signature
does not include the return type, nor does it include the params modifier that may be specified for the last parameter.
A
constructor signature
consists of the type and kind, such as value or reference. A constructor signature does not include the params modifier that may be specified for the last parameter.
An
indexer signature
consists of the type. An indexer signature does not include the element type.
An
operator signature
consists of the name of the operator and the type. An operator signature does not include the result type.
Signatures Example class
void MyFunc();
void MyFunc(int x);
void MyFunc(ref int x);
void MyFunc(out int x);
void MyFunc(int x, int y);
int MyFunc(string s);
int MyFunc(int x);
void MyFunc(string[] a);
void MyFunc(params string[] a);
The
ref and
out parameter modifiers are part of a signature.
MyFunc(int), MyFunc(ref int), and MyFunc(out int)
are all unique signatures.
The return type and the params modifier are not part of a signature, and it is not possible to overload based solely on return type or on the inclusion or exclusion of the params modifier.
Notice that there are some errors for the methods that contain duplicate signatures like
MyFunc(int)
and MyFunc(string[]) whose multiple signatures differ only by return type.