1
Reply

static void Main(string[] args){Console.Write(sum(1, 2));Console.Read();}public static int sum(int a, int b){return a + b;}public static int sum(int a, int b, int c = 3){return a + b + c;}will it work ? if yes, then which method ? if no, then runtime error / compile time error ?

Prashant Verma

Prashant Verma

Nov 09, 2015
152
0

    Output : 3yes it will work.Ref MSDN : if two candidates are judged to be equally good, preference goes to a candidate that does not have optional parameters for which arguments were omitted in the call. This is a consequence of a general preference in overload resolution for candidates that have fewer parameters.

    Prashant Verma
    November 09, 2015
    0