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
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
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 ---------------
----------------- 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
ASKER
If I do
private enum InitialValueType{number, date, string, Boolean, enum};
I get
Error 93 Identifier expected, 'string' is a keyword
Thanks
private enum InitialValueType{number, date, string, Boolean, enum};
I get
Error 93 Identifier expected, 'string' is a keyword
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
private Enum InitialValue
{
//list of things in enum
}