How to determine data type in run-time?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: How to determine data type in run-time?

Hybrid View

  1. #1
    Wesam Guest

    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



  2. #2
    Mattias Sjögren Guest

    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.

  3. #3
    Darell F. Butch Guest

    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.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center