Possible Duplicate:
C# 4: conflicting overloaded methods with optional parameters
I just have one small research and created next code.
namespace Test { class Program { public interface ITestA { void MethodA(int a, int b); } public class TestAClass : ITestA { public void MethodA(int a, int b) { Console.WriteLine("MethodA with param"); } public void MethodA(int a, int b, bool logic = true) { Console.WriteLine("MethodA logic with param"); } } public interface ITestB { void MethodA(int a, int b, bool logic = true); } public class TestBClass : ITestB { public void MethodA(int a, int b) { Console.WriteLine("MethodB with param"); } public void MethodA(int a, int b, bool logic = true) { Console.WriteLine("MethodB logic with param"); } } static void Main(string[] args) { var testA = new TestAClass(); testA.MethodA(1, 1); var testB = new TestBClass(); testB.MethodA(1, 1); } } }
I have a question why compiler always choose short method with 2 parameters. And of course all this work by the same way and without Interface.
Thanks