C#

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Thursday, 1 September 2016

Interview Question asked on immutable


Interview Question asked to me in an interview.
What will be the output of the below program ?

 using System;   
  using System.Collections.Generic;   
  using System.Linq;  
 namespace LinqDetails  
 {  
   class Program  
   {  
     static void Main(string[] args)  
     {  
       DateTime dt = Convert.ToDateTime("9/2/2016");  
       dt.AddDays(1);  
       Console.WriteLine(dt);  
       Console.ReadLine();  
     }  
   }  
 }  

 Output







Because DateTime is immutable. :)



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)'