TYPEs - GetType, typeof(), etc
Posted on 2007-04-11
Please explain to me about Types and the methodss GetType(something), typeof(something) and myobject.GetType()
They seems to all do subtley different things and I'm never sure how to use them.
For example, when serializing I need a type to create a new serializer:
dim foo as new XmlSerialzier(System.Data.DataView)
But what if I have an object reference and I want to pull its type out.... how do I do that? The various combinatuion of the above crash:
dim foo as new XmlSerialzier( GetType(MyObject) ) ' does not compile - "Type MyObject not defined"
dim foo as new XmlSerialzier( MyObject.GetType() ) ' compiles but crashes
dim foo as new XmlSerialzier( typeof( MyObject) ) ' does not compile - " 'Is' expected"
Please explain these different methods to me and tell me how to pull out and use the type of an object reference.