V
Vladimir Granitsky
Hi guys,
Please, look at the code below and try to step into it. The compiled code calls the loosely typed method public void Method1(object o) !?!?
Am I right that C# compiler does wrong overload resolution ?
I've used parameters of type object and string here, just to illustrate the problem. Really I have a bit more deep inheritance graph, and the things get more interesting if the strongly typed overload is like override public void Method1(BaseType x). When I call it with parameter of type SubType (that inherits BaseType) the right method is called.
Thanks for any useful points.
Regadrs,
Vladimir Granitsky
using System;using System.Diagnostics;namespace OverloadResolution{ public class Class1 { virtual public void Method1(string s) { Trace.WriteLine("Class1.Method1"); } } public class Class2 : Class1 { override public void Method1(string s) { Trace.WriteLine("Class2.Method1a"); } public void Method1(object o) { Trace.WriteLine("Class2.Method1b"); } } class Client { [STAThread] static void Main(string[] args) { string s = "blah"; Class2 o2 = new Class2(); o2.Method1(s); } }}
Please, look at the code below and try to step into it. The compiled code calls the loosely typed method public void Method1(object o) !?!?
Am I right that C# compiler does wrong overload resolution ?
I've used parameters of type object and string here, just to illustrate the problem. Really I have a bit more deep inheritance graph, and the things get more interesting if the strongly typed overload is like override public void Method1(BaseType x). When I call it with parameter of type SubType (that inherits BaseType) the right method is called.
Thanks for any useful points.
Regadrs,
Vladimir Granitsky
using System;using System.Diagnostics;namespace OverloadResolution{ public class Class1 { virtual public void Method1(string s) { Trace.WriteLine("Class1.Method1"); } } public class Class2 : Class1 { override public void Method1(string s) { Trace.WriteLine("Class2.Method1a"); } public void Method1(object o) { Trace.WriteLine("Class2.Method1b"); } } class Client { [STAThread] static void Main(string[] args) { string s = "blah"; Class2 o2 = new Class2(); o2.Method1(s); } }}