Solved

How to convert (DayOfWeek) to a list?

Posted on 2014-04-11
4
573 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
Comment Utility
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
Comment Utility
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 74

Expert Comment

by:käµfm³d 👽
Comment Utility
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 74

Expert Comment

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

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now