typeof vs. <object>.GetType() ?

  • Thread starter Thread starter Claus Konrad
  • Start date Start date
C

Claus Konrad

Hi

Any thoughtfull insight at to whether a difference exists between the two
functions mentioned above?
I am just wondering when to use the one over the other...??

Thanks!

/Claus
 
:
Any thoughtfull insight at to whether a difference exists between the two
functions mentioned above?
I am just wondering when to use the one over the other...??

Well, you can use "typeof" with a class name (no instance is required).
You need an instance to use the .GetType() method.

Console.WriteLine(typeof (System.Collections.Hashtable).ToString());
Console.WriteLine(new System.Collections.Hashtable().ToString());
 
In terms of the object returned there is no difference

--
Jared Parson [MSFT]
(e-mail address removed)

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
 
Back
Top