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?
Yes.
You can also do:
object c = new FooBar();
if(c is FooBar)
Console.WriteLine("FOOBAR!!!");
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With