C#

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Thursday, 1 September 2016

Common Interview question on method overloading


Is it overloaded ?What will be the output ?

using System;   
  using System.Collections.Generic;   
  using System.Linq;  
 namespace LinqDetails  
 {  
   class Program  
   {  
     static void Main(string[] args)  
     {  
       Console.WriteLine(Add(2, 2));   
       Console.ReadLine();  
     }  
     public static double Add(int a, double b)  
     {  
       return a + b;  
     }  
     public static double Add(double a, int b)  
     {  
       return a + b;  
     }  
   }  
 }  

Output:-

Yes it is overloaded. But the above program will give an compile time error.

Error:- The call is ambiguous between the following methods or properties: 'LinqDetails.Program.Add(int, double)' and 'LinqDetails.Program.Add(double, int)'


No comments:

Post a Comment