473,468 Members | 1,343 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How do I find the dynamically type

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
Aug 17 '06 #1
5 1133
Hello, tony!

tAssume I have this method
tpublic void foo(object obj);
tand I want to find out what type this obj is.
tHow do I do that?
tI 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
Aug 17 '06 #2
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
Aug 17 '06 #3
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.

--
Patrick Philippot - Microsoft MVP
MainSoft Consulting Services
www.mainsoft.fr

Aug 17 '06 #4
Marc Gravell <ma**********@gmail.comwrote:
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.

--
Jon Skeet - <sk***@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
Aug 17 '06 #5
Agreed - as this would handle interfaces correctly as well. I wasn't
thinking straight.

Cheers

Marc
Aug 18 '06 #6

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

Similar topics

5
by: nmtoan | last post by:
Hi, I could not find any answer to this simple question of mine. Suppose I have to write a program, the main parts of it are as follows: #include <blahblah.h> struct {
27
by: one man army | last post by:
Hi All- I am new to PHP. I found FAQTS and the php manual. I am trying this sequence, but getting 'no zip string found:'... PHP Version 4.4.0 $doc = new DomDocument; $res =...
5
by: stellstarin | last post by:
I have a html where fields are created and added dynamically on the client side. I use the AppendChild() call to create fields dynamically. On submit i try to get the value for all the...
1
by: vj | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file? I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to...
0
by: vijendra | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file?I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to...
2
by: jmarendo | last post by:
Hello, After reading through the "Table Basics - DOM - Refer to table cells" example at mredkj.com , I modified the code for my own purposes. In the modified version, I create a hyperlink and...
6
by: | last post by:
I have made some user controls with custom properties. I can set those properties on instances of my user controls, and I have programmed my user control to do useful visual things in response to...
0
by: =?Utf-8?B?U3JpZGhhcg==?= | last post by:
Hi, Usually in Visual studio 2003 when we include a crystal report it creates a class file for that report. And we will use that class to dynamically load the data. But I am not able to find...
2
by: Smithers | last post by:
Using 3.5, I am stuck in attempting to: 1. Dynamically load an assembly 2. Instantiate a class from that assembly (the client code is in a different namespace than the namespace of the...
2
by: korean_dave | last post by:
How can i use the find() function on a string that is composed of tons of symbols that cause errors... THis is my string: find("<html><head><meta name="qrichtext" content="1" /><style...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.