?
Solved

How to convert (DayOfWeek) to a list?

Posted on 2014-04-11
4
Medium Priority
?
742 Views
Last Modified: 2014-04-11
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
0
Comment
Question by:mousemat24
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 1000 total points
ID: 39993611
DayOfWeek is an Enum, so you can get the name from an integer using:
string name = Enum.GetName(typeof(DayOfWeek), 1);

Open in new window

0
 
LVL 8

Accepted Solution

by:
deepu chandran earned 1000 total points
ID: 39993837
HI,
Try use below code also

var UIculture = new System.Globalization.CultureInfo("en-US");
var dayName = UIculture.DateTimeFormat.GetDayName(DateTime.Today.DayOfWeek);

Thanks
Deepu
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39994118
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.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39994291
C'est la vie.
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question