C# 方法重载解析的编译器步骤
C#编译器在定位重载方法定义时遵循哪些步骤 假设我们有这样的代码:C# 方法重载解析的编译器步骤,c#,compiler-construction,overloading,C#,Compiler Construction,Overloading,C#编译器在定位重载方法定义时遵循哪些步骤 假设我们有这样的代码: class Test { public void m1(int i) { Console.WriteLine("int-arg method"); } public void m1(float f) { Console.WriteLine("float-arg method
class Test
{
public void m1(int i)
{
Console.WriteLine("int-arg method");
}
public void m1(float f)
{
Console.WriteLine("float-arg method");
}
}
class Program
{
static void Main(string[] args)
{
Test t = new Test();
t.m1(1);
t.m1(10.5f);
t.m1('a');
t.m1(10L);
t.m1(10.5);
}
}
编译器遵循什么协议来定位正确的方法定义?语言规范的基本上是您的答案。关闭as需要更多的关注。如果你问潜在的惊喜来自何处,那主要与算法有关,它涉及比较类型之间的转换。过载解决是C#中最复杂的部分,因此如果有意外情况,您通常需要详细地解决个别情况。好的,谢谢您的时间。