2

In my database I'm saving numbers. Each number has been allocated to a day. For example 1 equals Monday.

In my C# code I have an enum like:

enum day { Sunday=0, Monday, Tuesday, Wednesday, Thursday, Friday,Saturday  };

I want get current day from host and compare it with my database, for checking user access.

What is the best way to compare an enum value with a generic List<int>?

I took a look at this topic How to compare enum and int values? but it wasn't useful for me.

UPDATE:
I have user access in my program by day and time. I saved the days which can have access to app. the days had saved as integer; so when user wanna login I have to compare integer with enum. because I fetch from database one time, so I have List<int> of days. I dont know is there any better way to do it or not?!

Community
  • 1
  • 1
Iran_Girl
  • 389
  • 2
  • 8
  • 18

1 Answers1

2
List< int > allowedDays = new List<int> {0,1,4};

if (allowedDays.Contains((int)DateTime.Now.DayOfWeek))
                // do soemthing

Or something like that

Marc

mp3ferret
  • 1,143
  • 11
  • 16
  • 1
    thanks for spotting the syntax error - would have preferred it to be corrected to List allowedDays = new List {0, 1, 4}; Just think it looks nicer - not that I'm a code snob or anything ;) – mp3ferret Aug 25 '13 at 18:28
  • @Iran_Girl what was the problem with `IndexOf` in my comments(I deleted now) – I4V Aug 25 '13 at 18:35
  • @mp3ferret sorry but I thought it's better to change until some ones like me in zero level dont make mistake.. THANKS VERY MUCH FOR YOUR EFFICIENT REPLY :) – Iran_Girl Aug 25 '13 at 18:35
  • @I4V sorry my friend! because I found my answer in @mp3ferret, so I didn't try `IndexOf`. WHY you delete your post :-( it had useful and new codes for me :-( – Iran_Girl Aug 25 '13 at 18:39