?
What will be the output of the following C# code snippet?
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();
}
}
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();
}
}
Join the Discussion
Login to post a comment or share your explanation.
Login