Suppose you create a generic Object variable and assign it to a specific instance. If you do GetType(), will it get type Object or the type of the original class?
A:
Yes.
You can also do:
object c = new FooBar();
if(c is FooBar)
Console.WriteLine("FOOBAR!!!");
Alan
2008-11-24 23:14:55
+2
A:
Short answer: GetType() will return the Type of the specific object. I made a quick app to test this:
Foo f = new Foo();
Type t = f.GetType();
Object o = (object)f;
Type t2 = o.GetType();
bool areSame = t.Equals(t2);
And yep, they are the same.
kurious
2008-11-24 23:14:55
use: if(o is Foo) instead.
Alan
2008-11-24 23:15:31
A:
Calling GetType() will call the ACTUAL type. If you want to know the base type, you can call GetType().BaseType
Brian Genisio
2008-11-24 23:15:48