This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!
3.4 Signatures and overloading
Methods, constructors, indexers, and operators are characterized by their signatures:
- The signature of a method consists of the name of the method and the number, modifiers, and types of its formal parameters. The signature of a method specifically does not include the return type.
- The signature of a constructor consists of the number, modifiers, and types of its formal parameters.
- The signature of an indexer consists of the number and types of its formal parameters. The signature of an indexer specifically does not include the element type.
- The signature of an operator consists of the name of the operator and the number and types of its formal parameters. The signature of an operator specifically does not include the result type.
Signatures are the enabling mechanism for overloading of members in classes, structs, and interfaces:
- Overloading of methods permits a class, struct, or interface to declare multiple methods with the same name, provided the signatures of the methods are all unique.
- Overloading of constructors permits a class or struct to declare multiple constructors, provided the signatures of the constructors are all unique.
- Overloading of indexers permits a class, struct, or interface to declare multiple indexers, provided the signatures of the indexers are all unique.
- Overloading of operators permits a class or struct to declare multiple operators with the same name, provided the signatures of the operators are all unique.
The following example shows a set of overloaded method declarations along with their signatures.
interface ITest
{
void F(); // F()
void F(int x); // F(int)
void F(ref int x); // F(ref int)
void F(out int x); // F(out int)
void F(int x, int y); // F(int, int)
int F(string s); // F(string)
int F(int x); // F(int)
}
Note that parameter modifiers are part of a signature. Thus, F(int)
, F(ref int)
, and F(out int)
are all unique signatures. Furthermore note that even though the second and last method declarations differ in return types, their signatures are both F(int)
. Thus, compiling the above example would produce errors for the second and last methods.