重载具有相同名称和相同参数类型的2个方法

Swa*_*wag 1 c# asp.net

我有两个具有相同名称和相同参数类型的方法.我想重载那些,但它不起作用,因为我收到此错误:

"<Class-name> already defines a member called 'ChangeProfileInformation' 
 with the same parameter types"
Run Code Online (Sandbox Code Playgroud)

我有这样的事情:

public void ChangeProfileInformation(User user)
{
   a
   b
}

public void ChangeProfileInformation(User user)
{
   a
   c
   d
}
Run Code Online (Sandbox Code Playgroud)

有谁知道为什么这不起作用?

提前致谢!

Gua*_*nxi 6

重载意味着使用相同的函数名做不同的事情.为此,两个函数应该有不同的签名,否则编译器无法区分.你必须有不同的签名.


Bat*_*eba 5

编译器不知道选择哪一个:它会如何?您需要具有不同的名称或不同的参数类型。

或者,为什么不使用可选标志来更改函数的行为呢?