Click here to Skip to main content
15,887,338 members
Please Sign up or sign in to vote.
2.60/5 (2 votes)
See more:
Excuse my question, I bet this is an easy (and dumb) one!
I have a variable (Day), which I wish to set the value to two different enums, depending on the state of another variable (WeekPeriod). Its something like this:

enum Weekday
{
Monday,
Tuesday,
Wednesday,
Thursday,
Friday
}

enum Weekend
{
Saturday,
Sunday
}
...
if(WeekPeriod == "Weekend")
{
Weekday Day;
}
else
{
Weekend Day;
}

I hope this makes sense - do you have any suggestions?!!
Thanks in advance
Mike
Posted

1 solution

it is possible to declare integer variable and then use cast operation
C#
int Day;
if(WeekPeriod == "Weekend")
 {
   Day = (int)someValue1; // someValue1 is Weekend
 }
 else
 {
   Day = (int)someValue2; // someValue2 is Weekday
 }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900