• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 317
  • Last Modified:

How to show days using enum

Hi

I have the following prop:

public int Day { get; set; }

the data in SQL will be an int as well, but what i want to do is show the string

Sat, Sun, Mon, Tue, Wed, Thu, Fri

Sat being 1

How does one do this using enums?

thanks
0
mousemat24
Asked:
mousemat24
  • 2
1 Solution
 
AndyAinscowFreelance programmer / ConsultantCommented:
With a case statement.
String s;
            switch (yourday)
            {
                case Sat: s = "Sat"; break;
                case Sun: s = "Sun"; break;
and so on where Sat, Sun are the enumerated values and yourday is the variable containing the day you want displayed
            }
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
ps.  If you were doing this in multiple places you could build a function that takes the enum variable and returns a string.
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now