C# Interview Questions and Answers Part 2

1)   What is the output  for below program?

static void Main(string[] args)

    {

        bool b = 1;

        Console.WriteLine(b);

        Console.ReadLine();

    }

OUTPUT :  

 Error     1    Constant value '1' cannot be converted to a 'bool'         

2)   What is the output for below program?

 static void Main(string[] args)

    {

        int a = null;

        Console.WriteLine(a);

        Console.ReadLine();

    }

OUTPUT :  

Error    1   Cannot convert null to 'int' because it is a non-nullable value type      

 

3)   What is the output?

 

  static void Main(string[] args)

    {

        var a = 10;

        var b = 10.5;

        Console.WriteLine(a.GetType());

        Console.WriteLine(b.GetType());

        Console.ReadLine();

    }

OUTPUT :  

         System.Int32

        System.Double

 

4)    Which of the following is an 8-byte Integer?

       A.  Char                 B.    Long                     C.   Short                      D.    byte            E.     int

      Ans;-B

5)    What is the output?

static void Main(string[] args)

    {

        string s1 = "1234";

        int res=int.Parse(s1);

        Console.WriteLine(s1);

        Console.ReadLine();

    }

OUTPUT :  

       1234



Subscribe

Receive Quality Tutorials Straight in your Inbox by submitting your Email below:

Delivered by FeedBurner

Protected by Copyscape Duplicate Content Checker