访问修饰符是 C# 中方法签名的一部分吗?

Is access modifier part of Method Signature in C#?

这里的 MSDN https://msdn.microsoft.com/en-us/library/ms173114.aspx 说像 "private/protected" 这样的访问修饰符是 c# 中方法签名的一部分。

不过下面这个link好像不是这么想的Method Signature in C#

是哪一个?还有静态方法呢?关键字 "static" 是方法签名的一部分吗?

谢谢

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 方法签名:

  • 调用约定*
  • 泛型参数的个数,如果方法是泛型的,
  • 如果调用约定指定这是一个实例方法并且拥有方法定义属于类型 T 那么 this 指针的类型是...[此处无关]
  • 一个包含零个或多个参数签名的列表——方法的每个参数都有一个,
  • 结果值的类型签名(如果生成的话)。

备注:

* 调用约定包括 static/instance 规范。

供参考,II.15.3调用约定:

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.

结论:none 的方法签名定义包含访问修饰符。

不相信静态是方法签名的一部分,因为即使调用了静态方法:

Classname.StaticMethodName(..);

调用实例方法时:

var o = new Classname();
o.MethodName(..);

它仍然定义了匹配签名的方法和参数。有关静态与实例方法和签名的更多信息,请参见:Static and Instance methods with the same name?

访问级别不是签名的一部分,因为您不能:

public void DoThis();

private void DoThis();

这两种方法具有相同的签名,因为签名基于方法、泛型参数和方法参数/类型。

以下有效:

public void DoThis();
private void DoThis(int x);

或:

public void DoThis();
private int DoThis<int>();

简单的说,不是。方法签名是由它的方法名和它接受的参数决定的。