c# - Methods overloading -


When I call EntryPoint with a parameter type of TemplateA, then I always get an exception, because first Overload is always called
What I expect to happen is that due to dynamic binding, the most specific method (second surcharge) will be called.
Any ideas why?

  Private objects _obj; Public Zero EntryPoint (Object P) {myFunc (P); } // First surcharge private zero myFunc (object container) {throwing new NotImplementedException; } // second overload private zero myFunc (TemplateA template) {_obj = new ObjTypeA (template); } // Third Overload Private Zero myFunc (TemplateB Template) {_obj = New ObjTypeB (template); }  

If you use then you can use it in C # 4.0 Will be able to. Dynamic instead of object . Download Visual Studio 2010 Beta, if you want to give it a try, the compiler chooses exactly the same way to call the parameter based on the compile-time type.

It is not clear from your question whether you know about simple single dispatch polymorphism, because it will solve your example problem.