How to determine data type in run-time?
Hi all!
I need to know the data type of some objects at the run-time but I don't
know how?? I use the TAG property of some controls in order to store some
important data, but this data is in different types (i.e. oncs INT and once
STRING) and when I want to read the data I have to cast the TAG property and
here is my problem, I don't know which data type is in the data and thus I
can't determine the data type to which I should cast the TAG property, could
you help me?
Thanks in advance,
Wesam
Re: How to determine data type in run-time?
Wesam,
> I need to know the data type of some objects at the run-time but I don't
>know how?? I use the TAG property of some controls in order to store some
>important data, but this data is in different types (i.e. oncs INT and once
>STRING) and when I want to read the data I have to cast the TAG property and
>here is my problem, I don't know which data type is in the data and thus I
>can't determine the data type to which I should cast the TAG property, could
>you help me?
if ( tag is int )
DoStuffWithInt( (int)tag );
else if ( tag is string )
DoStuffWithString( (string)tag );
and so on.
Mattias
--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Re: How to determine data type in run-time?
"Wesam" <public_2000@hotmail.com> wrote:
>Hi all!
>
> I need to know the data type of some objects at the run-time but I don't
>know how?? I use the TAG property of some controls in order to store some
>important data, but this data is in different types (i.e. oncs INT and once
>STRING) and when I want to read the data I have to cast the TAG property
and
>here is my problem, I don't know which data type is in the data and thus
I
>can't determine the data type to which I should cast the TAG property, could
>you help me?
>
>Thanks in advance,
>
>Wesam
>
>
Every object in CLR is derived from the base object OBJECT. One of the functions
of the OBJECT is, GetType(). This will return the type of what ever is stored
on the Tag property.