473,325 Members | 2,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

GetType() on a class w/o instantiate an object

Hello,

I'm just wondering if we somehow we can obtain the System.Type of a class
w/o instantiating an object of the class.

Right now I have to do this and it doesn't seem efficient, type is a static
information, why would we need to instantiate an object of the class?

MyObject = new MyClass();
System.Type = MyObject.GetType();

thanks!
Nov 15 '05 #1
3 1390
Zeng <zz*@nonospam.com> wrote:
I'm just wondering if we somehow we can obtain the System.Type of a class
w/o instantiating an object of the class.

Right now I have to do this and it doesn't seem efficient, type is a static
information, why would we need to instantiate an object of the class?

MyObject = new MyClass();
System.Type = MyObject.GetType();


Use the typeof operator:

Type t = typeof(MyClass);

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
TypeOf(MyClass)

"Zeng" <zz*@nonospam.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hello,

I'm just wondering if we somehow we can obtain the System.Type of a class
w/o instantiating an object of the class.

Right now I have to do this and it doesn't seem efficient, type is a static information, why would we need to instantiate an object of the class?

MyObject = new MyClass();
System.Type = MyObject.GetType();

thanks!

Nov 15 '05 #3
Brother Zeng,

Walk down the path of "typeof()" ... he will show you the way.

"Zeng" <zz*@nonospam.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hello,

I'm just wondering if we somehow we can obtain the System.Type of a class
w/o instantiating an object of the class.

Right now I have to do this and it doesn't seem efficient, type is a static information, why would we need to instantiate an object of the class?

MyObject = new MyClass();
System.Type = MyObject.GetType();

thanks!

Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: JohnnySparkles | last post by:
Hi everyone, I'm currently writing an application which uses the XmlSerializer class to serialize/deserialize objects to/from xml. Now when deserializing an XmlDocument back into the object,...
7
by: Drew McCormack | last post by:
I have a C++ template class which contains a static variable whose construction registers the class with a map. Something like this: template <typename T> class M { static Registrar<M>...
6
by: Brad | last post by:
I am creating a class (not a control) which implements IStateManager. I've created the class and all of the implementations (LoadView, SaveViewState, etc...). My Question is: How do I...
10
by: Bob | last post by:
This has been bugging me for a while now. GetType isn't availble for variables decalred as interface types, I have to DirectCast(somevariable, Object). In example: Sub SomeSub(ByVal...
5
by: Matthew | last post by:
I have a nice little Sub that saves data in a class "mySettings" to an XML file. I call it like so: Dim mySettings As mySettings = New mySettings mySettings.value1 = "someText" mySettings.value2...
6
by: Paul | last post by:
I have two projects in one solution. One is called Frontier and holds all my base user controls, classes, etc. that are used over multiple applications. The second is my application project...
4
by: Pupeno | last post by:
Hello, I want to jump over a method in the class hierarchy, that is: If I have class A(object), clas B(A), class C(B) and in C, I want a method to do exactly what A does but not what B does in...
1
by: hardieca | last post by:
Hi, I have an .aspx page that needs to instantiate an object whose type in not known until runtime. The definition of said object resides in /App_code/CMS.cs CMS.cs ==================...
0
by: emin.shopper | last post by:
I had a need recently to check if my subclasses properly implemented the desired interface and wished that I could use something like an abstract base class in python. After reading up on metaclass...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.