What will be the output of the following C# code snippet? [code] class program { public static void Main(string[] args) {

Trang Esther

New member
What will be the output of the following C# code snippet?
Code:
 class program
 {
     public static void Main(string[] args)
     {
         try
         {
             throw new NullReferenceException("C");
             Console.WriteLine("A");
         }
         catch (ArithmeticException e) 
         {
             Console.WriteLine("B");
         }
         Console.ReadLine();
     }
 }
A. A
B. B
C. Compile time error
D. Runtime error
 
Answer: d
Explanation: Try block is throwing NullPointerException but the catch block is used to counter Arithmetic Exception. Hence NullPointerException occurs since no catch is there which can handle it, runtime error occurs.
 

Tìm kiếm

Back
Top