Solved

How to convert (DayOfWeek) to a list?

Posted on 2014-04-11
4
623 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
  • 2
4 Comments
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 250 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 250 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

803 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