Solved

How to convert (DayOfWeek) to a list?

Posted on 2014-04-11
4
654 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 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

696 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