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