Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jun 2003
    Location
    California
    Posts
    231
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Data types with unknown data

    Variables must be defined before they can be used.
    But what if you dont know what data type to use for a variable called "x" because you dont know what type of data the user will enter for x. x could be a name, a number, or a symbole. So in a case like this, how would you define x?.

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Cincinnati, OH
    Posts
    545
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Depending on the language you can declare it as object. In c#

    public object _foo;

  • #3
    Regular Coder
    Join Date
    Dec 2003
    Posts
    367
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes. It depends on the language. Many languages have variant types (like VB), that can hold any type of data, sometimes the language _only_ has variants (like VBScript).
    For strongly typed languages, you could allocate that variable dynamically or something, in object-oriented languages you could make a class hierarchy that contains all the possible types.
    Etc, etc, etc.

    shmoove


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •