C# Interview Questions and Answers Part 7

1)   What is the output?

static void Main(string[] args)

    {

        char a;

        Console.WriteLine(a);

        Console.ReadLine();

    }

 

OUTPUT :  

            Error  1  Use of unassigned local variable 'a'    

 

2)   What is the output?

 static void Main(string[] args)

    {       

                      int a = 10;

        Console.WriteLine(A);

        Console.ReadLine();  

    }

OUTPUT :

Error   1  The name 'A' does not exist in the current context      

 

3)   The below code is valid or Invalid?

static void Main(string[] args)

        {

            byte b =-10;

            Console.WriteLine(b);

            Console.ReadLine();

        }

OUTPUT :  

Error   1  Constant value '-10' cannot be converted to a 'byte'     

 

4)   What is the output?

static void Main(string[] args)

        {

            string s = "dotnet";

            object a = s;

            Console.WriteLine(a);

            int i = 10;

            object b = i;

            Console.WriteLine(b);

            Console.ReadLine();

        }

OUTPUT :  

dotnet

10

5)   What is the output?

static void Main(string[] args)

        {

            int i = 1;

            Console.Write(i++);

            Console.Write(i);

            Console.Write(i--);

            Console.Write(i);

            Console.Write(--i);

            Console.ReadLine();

        }

OUTPUT :  

12210






Subscribe

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

Delivered by FeedBurner

Protected by Copyscape Duplicate Content Checker