Link to home
Start Free TrialLog in
Avatar of mousemat24
mousemat24

asked on

How to convert (DayOfWeek) to a list?

Hi

There is a (DayOfWeek) prop in .net

what I want to do is create a list based on that, can someone please help me?

also it must work with int i.e.

if I have a day with int which is set to 2 doing (DayOfWeek)item.day will show Tuesday

Hope this makes sense?

thanks
SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

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
ASKER CERTIFIED SOLUTION
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
if I have a day with int which is set to 2 doing (DayOfWeek)item.day will show Tuesday

The great thing about enums in .NET is that when you call their ToString method, you get back the name of the member, not its value:

e.g.

string day = ((DayOfWeek)item.day).ToString();  // "day" holds "Tuesday"

Open in new window


Just make sure you are working with an instance of the enum, not the integer itself--i.e. cast it as in the above.
C'est la vie.