C# Coding Interview Questions (Part – 3)

Datetime:2016-08-22 22:12:49          Topic: C#           Share

1. What happens when you compile and run the below program?

public class Program
    {      
      public static void Main(string[] args)
        {
          char x = 'X';
          int i = 0;
          Console.WriteLine (true  ? x : 0);
          Console.WriteLine(false ? i : x); 
        }
    }

Output:

88

88

2. Predict the output for below program.

  public class Program
    {
 
        public static void Main(string[] args)
        {
            int x = 1975;
            int y = 2015;
            x ^= y ^= x ^= y;
            Console.WriteLine("x = " + x + "; y = " + y);
        }
    }

Output:

x = 0;Y=1975

3. What will be the output for below program?

public class Program
    {
        public static bool isOdd(int i) {
          return i % 2 == 1;
      }
  
      public static void Main(string[] args)
        {
    
        }
    }

Output:

The program will be compiled successfully

4. Predict the output for below Program

  public class Program
    {
        public static void Main(string[] args)
        {
            String letters = "ABC";
            char[] numbers = { '1', '2', '3' };
            Console.WriteLine(letters + " easy as " + numbers);
        }
 
    }

Output:

ABC easy as System.Char[]

5. What will be the output for below program?

public class Program
    {
      public static void Main(string[] args)
        {
            int i = 5;
            int j = 6;
        while (i <= j && j <= i && i != j) {
            Console.WriteLine("Good Day !!");
          }
        }
    }

Output:

The program will be compiled successfully with no output.

6. Predict the output for below Program.

public class Program
    {
    public static void Main(string[] args)
        {
          Console.WriteLine ("iexplore:");
          http://www.google.com;
          Console.WriteLine(":maximize"); 
        }
    }

Output:

iexplore:

:maximize

7. What will be the output for below program?

public class Program
    {
    public static void Main(string[] args)
        {
        int i=5;
        while (i != i + 0) {
            Console.WriteLine("Hello");
          }
        }
    }

Output:

The program will be compiled successfully with no output

8. Predict the Output for below program

 public class Program
    {
        static void Main(string[] args)
        {
            work();
            Console.WriteLine("Hello");
        }
 
        private static void work()
        {
            try
            {
                work();
            }
            finally
            {
                work();
            }
        }
    }

Output:

StackOverflowException

9. What will be the output for below program?

 public class Program
    {
        public static void Main(string[] args)
        {
            ProgramPuzzler = null;
            Console.WriteLine(Program.get());
        }
        private static String get()
        {
            return "i am a C# puzzler";
        }
    }

Output:

i am a C# puzzler

10. Predict the output for below program?

  public class Program
    {
        public static void Main(string[] args)
        {
            Double i = Double.NaN;
            while (i != i)
            {
                Console.WriteLine("Hello");
            }
        }
    }

Output:

It will be an infinite loop with ‘Hello’

You may also Like:

C# Interview Questions for Experienced professionals (Part – 1) C# Interview Questions for Experienced professionals (Part – 2) C# Interview Questions for Experienced professionals (Part – 3) C# Interview Questions for Experienced professionals (Part – 4) C# Interview Questions for Experienced professionals (Part – 5) C# Interview Questions for Experienced professionals (Part – 6) C# Interview Questions for Experienced professionals (Part – 7) C# Interview Questions for Experienced professionals (Part – 8) C# Interview Questions for Experienced professionals (Part – 9)

Thanks for Visiting !!

© 2016,admin. All rights reserved.





About List