Hello!!
Assume I have this method
public void foo(object obj);
and I want to find out what type this obj is.
How do I do that?
I can look in the code but assume the code is very complicated.
//Tony
Marc Gravell - 17 Aug 2006 09:25 GMT
assuming obj isn't null, then obj.GetType() will return you the Type object,
which gives you lots of info.
If possible, avoid == (or ReferenceEquals) on types (unless you really mean
it) - this is often a bug, as you should also check .IsSubclassOf().
Any use?
Marc
Jon Skeet [C# MVP] - 17 Aug 2006 19:53 GMT
> assuming obj isn't null, then obj.GetType() will return you the Type object,
> which gives you lots of info.
> If possible, avoid == (or ReferenceEquals) on types (unless you really mean
> it) - this is often a bug, as you should also check .IsSubclassOf().
... or IsAssignableFrom.

Signature
Jon Skeet - <skeet@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
Marc Gravell - 18 Aug 2006 08:52 GMT
Agreed - as this would handle interfaces correctly as well. I wasn't
thinking straight.
Cheers
Marc
Patrick Philippot - 17 Aug 2006 09:25 GMT
Hi,
> Assume I have this method
> public void foo(object obj);
> and I want to find out what type this obj is.
> How do I do that?
Any object in .Net is derived from the root Object class. And Object has a
method named GetType that will do exactly what you want.

Signature
Patrick Philippot - Microsoft MVP
MainSoft Consulting Services
www.mainsoft.fr
Vadym Stetsyak - 17 Aug 2006 09:26 GMT
Hello, tony!
t> Assume I have this method
t> public void foo(object obj);
t> and I want to find out what type this obj is.
t> How do I do that?
t> I can look in the code but assume the code is very complicated.
you can call obj.GetType().
--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com