Examveda

What will be the output of the following C# code snippet?
class A {}
class B : A {}
class CheckCast 
{
    static void Main() 
    {
        A a = new A();
        B b = new B();
        b = a as B;
        b = null;
        if(b==null)
        Console.WriteLine("The cast in b = (B) a is NOT allowed.");
        else
        Console.WriteLine("The cast in b = (B) a is allowed");
    }
}

A. Run time error

B. The cast in b = (B) a is NOT allowed

C. The cast in b = (B) a is allowed

D. Compile time error

Answer: Option B


Join The Discussion

Related Questions on LINQ (Language Integrated Query) in C Sharp