Link to home
Start Free TrialLog in
Avatar of paulwhelan
paulwhelan

asked on

storing data?

Hi

Im making changes to some code.

We had a variable

private string InitialValue

which was used for five different 'data types' (number, date, string, boolean and enumerator)
so it was suggested that instead of it being

private string InitialValue

for each of the five it should be

private object InitialValue

and then within 'number' it should be

private decimal InitialValue

and within 'date' it should be

private datetime InitialValue

and within 'string' it should be

private boolean InitialValue

and within 'boolean' it should be

private datetime InitialValue



with the aim being that only decimals will be entered as the Initial Value for a number, only booleans will be entered as the Initial Value for booleans.

My question is what should it be for enumerator?

Any questions let me know

Thanks
Paul
Avatar of levyuk
levyuk

It should be

private Enum InitialValue
{
//list of things in enum
}
I think levyuk meant InitialValueType as an addition to InitialValue, you will need both.
----------------- CODE ----------------
private enum InitialValueType {number, date, string, boolean and enumerator};

private object initialValue;
private InitialValueType initialValueType;
-------------- END CODE ---------------

However, you could do this without an enum doing something simple like this in your code because you are going to have to have an if statement to check what the initialValueType is:
----------------- CODE ----------------
initialValue = 10;

if (initialValue.GetType() == typeof(int))
{
    MessageBox.Show("a number");
}
else if (initialValue.GetType() == typeof(DateTime))
{
    MessageBox.Show("a date");
}
-------------- END CODE ---------------
YEah that is better, it was early afterall :P
Avatar of paulwhelan

ASKER

If I do

private enum InitialValueType{number, date, string, Boolean, enum};


I get

Error      93      Identifier expected, 'string' is a keyword      

Thanks
ASKER CERTIFIED SOLUTION
Avatar of jonorossi
jonorossi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial