参数类型的顺序是否会更改 C# 中方法的签名?
Does the order of parameter types change the signature of a method in C#?
对于以下方法:参数类型的顺序是否会产生唯一的方法签名?
static void PrintOrderCost(double totalCost, string customerName)
{
}
以上方法签名:PrintOrderCost(double, string)
static void PrintOrderCost(string customerName, double totalCost)
{
}
以上方法签名:PrintOrderCost(string, double)
这是在C# Language Specification中指定的:
The signature of a method consists of the name of the method, the number of type parameters and the type and kind (value, reference, or output) of each of its formal parameters, considered in the order left to right. [...]
所以是的,顺序是签名的一部分,所以不同的顺序是不同的签名。显示的两个方法是两个重载,因为:
Overloading of methods permits a class, struct, or interface to declare multiple methods with the same name, provided their signatures are unique within that class, struct, or interface.
对于以下方法:参数类型的顺序是否会产生唯一的方法签名?
static void PrintOrderCost(double totalCost, string customerName)
{
}
以上方法签名:PrintOrderCost(double, string)
static void PrintOrderCost(string customerName, double totalCost)
{
}
以上方法签名:PrintOrderCost(string, double)
这是在C# Language Specification中指定的:
The signature of a method consists of the name of the method, the number of type parameters and the type and kind (value, reference, or output) of each of its formal parameters, considered in the order left to right. [...]
所以是的,顺序是签名的一部分,所以不同的顺序是不同的签名。显示的两个方法是两个重载,因为:
Overloading of methods permits a class, struct, or interface to declare multiple methods with the same name, provided their signatures are unique within that class, struct, or interface.