Examveda

What will be the output of the following C# code snippet?
class B { }
class A : B { }
class Program
{
    static void Main(string[] args)
    {
        A a = new A();
        B b = new B();
        if (a is A) 
        Console.WriteLine("a is an A");
        if (b is A)
        Console.WriteLine("b is an A because it is derived from A");
        if (a is B)
        Console.WriteLine("This won’t display -- a not derived from B");
        Console.ReadLine();
    }
}

A. a is an A
This won't display -- a not derived from B

B. a is an A
b is an A because it is derived from A

C. b is an A because it is derived from A
This won't display -- a not derived from B

D. "Both "a is an A
This won't display - a not derived from B" & "a is an A
b is an A because it is derived from A"

Answer: Option A


Join The Discussion

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