Reputation: 399
MSDN here https://msdn.microsoft.com/en-us/library/ms173114.aspx says access modifiers like "private/protected" are part of method signature in c#.
However this link below doesnt seem to think so Method Signature in C#
Which one is it? Also what about a static method? Is the keyword "static" part of method signature?
thanks
Upvotes: 2
Views: 1640
Reputation: 60085
C# 5.0 specification, 1.6.6.Methods:
The signature of a method consists of the name of the method, the number of type parameters and the number, modifiers, and types of its parameters. The signature of a method does not include the return type.
CLI specification, I.8.6.1.5 Method signatures:
Notes:
* Calling convention includes static/instance specification.
For reference, II.15.3 Calling convention:
A calling convention specifies how a method expects its arguments to be passed from the caller to the called method. It consists of two parts: the first deals with the existence and type of the this pointer, while the second relates to the mechanism for transporting the arguments.
Conclusion: none of the definitions of method signature includes access modifiers.
Upvotes: 4
Reputation: 50728
In don't believe is static is part of the method signature because even though static methods are called:
Classname.StaticMethodName(..);
While instance methods are called:
var o = new Classname();
o.MethodName(..);
It still defines methods and parameters that match for the signature. See this for more on the static vs instance methods and signature: Static and Instance methods with the same name?
Access level is not part of the signature because you can't have:
public void DoThis();
private void DoThis();
Both methods have the same signature because signature is based on method, generic parameter(s), and method parameter(s)/types.
The following are valid:
public void DoThis();
private void DoThis(int x);
OR:
public void DoThis();
private int DoThis<int>();
Upvotes: 0
Reputation: 725
Simply, No. Method signature is determined by its method name and the parameters accepted by it.
Upvotes: 0