Hi
Is there any C# equivalent for the C++ keyword typeid?
or typeid(?).name()?
2 replies to this topic
#1
Posted 06 February 2012 - 07:00 PM
I wrote this ebook! Will you translate it into English for free!?:confused: PM me!
|
|
|
#2
Posted 09 April 2012 - 06:00 AM
yes, you have : FieldInfo.FieldType
Suit yourself to this example :
http://stackoverflow...specific-member
if you are going that kind of programming i suggest you to research a little about Reflection
Suit yourself to this example :
http://stackoverflow...specific-member
if you are going that kind of programming i suggest you to research a little about Reflection
#3
Posted 09 April 2012 - 07:14 PM
There are two ways (in regards of C++ equivalent) to get type information about an object.
2. If you want to get information about a type for which you have an instance of that type, you can use GetType method of that instance. GetType is a member of System.Object class, so you will get it in every class.
There are other ways, you can use to find type information -- Reflection.
- If you want to get information about a type without having an instance of that type, there is 'typeof' builtin operator in C#.
// Suppose you need to get type information about class Form1 (the default class in a form application) Type type = typeof(Form1); Console.WriteLine(type.Name); Console.WriteLine(type.FullName);
2. If you want to get information about a type for which you have an instance of that type, you can use GetType method of that instance. GetType is a member of System.Object class, so you will get it in every class.
// Suppose you need to get type information from an instance form1 of type Form1. Type type = form1.GetType(); Console.WriteLine(type.Name); Console.WriteLine(type.FullName);
There are other ways, you can use to find type information -- Reflection.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top










