Examveda

What will be the output of the following C# code?
static void Main(string[] args)
{
    int a = 10, b = 0;
    int result;
    Console.Out.WriteLine("This will generate an exception.");
    try
    {
        result = a / b; // generate an exception
    }
    catch (DivideByZeroException exc)
    {
        Console.Error.WriteLine(exc.Message);
    }
    Console.ReadLine();
}

A. This will generate an exception

B. 0

C. Compile time error

D. This will generate an exception
Attempted to Divide by Zero

Answer: Option D


Join The Discussion

Related Questions on File Handling and Input Output in C Sharp