473,405 Members | 2,349 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,405 software developers and data experts.

How to get instance Type from Type.GetType function

I am trying to use Type.GetType(name of type in string format) to get an
instance Type. For example: Type t = Type.GetType("System.Data.DataTable").
I have no trouble to get a value type For example: Type t =
Type.GetType("System.String").
Nov 16 '05 #1
3 17970
Did you try "typeof(...)" ?

- Sahil Malik
You can reach me thru my blog -
http://www.dotnetjunkies.com/weblog/sahilmalik

"da*******@opco.com" <da*******@opco.com@discussions.microsoft.com> wrote in
message news:81**********************************@microsof t.com...
I am trying to use Type.GetType(name of type in string format) to get an
instance Type. For example: Type t =
Type.GetType("System.Data.DataTable").
I have no trouble to get a value type For example: Type t =
Type.GetType("System.String").

Nov 16 '05 #2
da*******@opco.com <da*******@opco.com> wrote:
I am trying to use Type.GetType(name of type in string format) to get an
instance Type. For example: Type t = Type.GetType("System.Data.DataTable").
I have no trouble to get a value type For example: Type t =
Type.GetType("System.String").


typeof is the best way of doing this if you know the name in advance.
If you don't, you also need to know the assembly the type is in -
Type.GetType only looks in the currently executing assembly and
mscorlib unless you specify the assembly name as well.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3
You need to add the assembly name in for any type that is not in the corrent assembly or mscorlib. So

Type t = Type.GetType("System.Data.DataTable, System.Data, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");

Will work (for version 1.1 of the framework - if you're using 1.0 use the version number for that one)

Btw: System.String is not a Value Type, it a Reference Type

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<#e*************@TK2MSFTNGP11.phx.gbl>

Did you try "typeof(...)" ?

- Sahil Malik
You can reach me thru my blog -
http://www.dotnetjunkies.com/weblog/sahilmalik

"da*******@opco.com" <da*******@opco.com@discussions.microsoft.com> wrote in
message news:81**********************************@microsof t.com...
I am trying to use Type.GetType(name of type in string format) to get an
instance Type. For example: Type t =
Type.GetType("System.Data.DataTable").
I have no trouble to get a value type For example: Type t =
Type.GetType("System.String").


---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.770 / Virus Database: 517 - Release Date: 27/09/2004

[microsoft.public.dotnet.languages.csharp]
Nov 16 '05 #4

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

Similar topics

4
by: Chris Bower | last post by:
Reposted from aspnet.buildingcontrols: Ok, I've got a bunch of derived controls that all have a property Rights of type Rights (Rights is an Enumerator). I wrote a custom TypeConverter so that I...
2
by: S. Justin Gengo | last post by:
Hi, I've created a component that allows me to store database information for various types of databases my company uses. It uses a collection for each type of database. Everything is working...
5
by: Jarod_24 | last post by:
I got a object of type 'Control' passed as a argument to a subroutine of mine. The object is either a Combobox or a TextBox. I thought the .GetType could be used to check what type of object it...
6
by: Charles Law | last post by:
I want to do something like this: obj = CType(value, Value.Type) Well, not exactly, but I think that captures the essence. I realise it won't work as I have written it, and it looks a bit like...
12
by: Michael Maes | last post by:
Hello, I have a BaseClass and many Classes which all inherit (directly) from the BaseClass. One of the functions in the BaseClass is to (de)serialize the (inherited) Class to/from disk. ...
16
by: Dennis | last post by:
I have a class named "myclass" and an arraylist containing elements of type "MyClass". I want to get the value of a property of "MyClass" (a string type) for one of the arraylist elements. I...
6
by: wu jianhua | last post by:
hi. If I have a form, like FrmAbout, can I create a form instance only with a string "FrmAbout"? not like : Form frm = new FrmAbout(); I want the code : Form frm = createInstance( "FrmAbout" );...
10
by: Arpan | last post by:
Consider the following code that adds a table to a DataSet dynamically: <script runat="server"> Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) 'Create an empty DataSet Dim dSet As...
2
by: Jordi Julią | last post by:
Hello, I need to create with VB2005 an instance of one of the classes of the project in run time. For example: - The Namespace root and the name of the project are he himself: "Project" -...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.