What will be the output of the following C# code snippet?
class Program
{
public static void Main(string[] args)
{
try
{
int a = args.Length;
int b = 10 / a;
Console.WriteLine(a);
try
{
if (a == 1)
a = a / a - a;
if (a == 2)
{
int[] c = { 1 };
c[8] = 9;
}
}
catch (IndexOutOfRangeException e)
{
Console.WriteLine("TypeA");
}
}
catch (ArithmeticException e)
{
Console.WriteLine("TypeB");
}
Console.ReadLine();
}
}
class Program
{
public static void Main(string[] args)
{
try
{
int a = args.Length;
int b = 10 / a;
Console.WriteLine(a);
try
{
if (a == 1)
a = a / a - a;
if (a == 2)
{
int[] c = { 1 };
c[8] = 9;
}
}
catch (IndexOutOfRangeException e)
{
Console.WriteLine("TypeA");
}
}
catch (ArithmeticException e)
{
Console.WriteLine("TypeB");
}
Console.ReadLine();
}
}
A. TypeA
B. TypeB
C. 0TypeA
D. Compile time error
Answer: Option B
Join The Discussion