Jump to content

typeid

- - - - -

  • Please log in to reply
2 replies to this topic

#1
irancplusplus

irancplusplus

    Learning Programmer

  • Members
  • PipPipPip
  • 65 posts
Hi
Is there any C# equivalent for the C++ keyword typeid?
or typeid(?).name()?
I wrote this ebook! Will you translate it into English for free!?:confused: PM me!

#2
BlackRabbit

BlackRabbit

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 253 posts
  • Location:ten steps forward
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 ;)

#3
kernelcoder

kernelcoder

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 288 posts
  • Location:Dhaka
  • Programming Language:C, Java, C++, C#, Visual Basic .NET
  • Learning:Objective-C, PHP, Python, Delphi/Object Pascal
There are two ways (in regards of C++ equivalent) to get type information about an object.
  • 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