View Full Version : Data types with unknown data

03-30-2004, 04:15 AM
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?.

03-30-2004, 04:29 AM
Depending on the language you can declare it as object. In c#

public object _foo;

03-30-2004, 10:07 AM
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.