confirmed. Second, the cast must be made. These two steps can be combined into one through
462
P a r t I :
T h e C # L a n g u a g e
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");
}
}
Here is the output, which is the same as before:
The cast in b = (B) a is NOT allowed.
In this version, the
as
statement checks the validity of the cast and then, if valid, performs
the cast, all in one statement.
Using typeof
Although useful in their own ways, the
Do'stlaringiz bilan baham: