Jon Skeet [C# MVP] <sk***@pobox.comwrote:
<snip>
I can see how the opposite would happen, just by virtue of derived
classes where myClass refers to an instance of a class derived from
Class - but I can't see why the first would be false and the second
true.
Ooh - I've worked out a nasty bit of code where it would be the way
round you said. It's dirty though:
using System;
class EvilType
{
public new Type GetType()
{
return typeof(InnocentType);
}
}
class InnocentType
{
}
class Test
{
static void Main()
{
EvilType evil = new EvilType();
Console.WriteLine ("evil is InnocentType? {0}",
evil is InnocentType);
Console.WriteLine ("evil.GetType()==typeof(InnocentType)? {0}",
evil.GetType()==typeof(InnocentType));
}
}
The cast would also succeed if you had an explicit conversion from
EvilType to InnocentType.
I feel like I ought to have a bath after writing that...
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog:
http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too