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
  • 439
  • 2
  • 11
  • 18
  • 3
    Could you include more code and/or describe your question better? Why would an enum value ever compare to be equal to a generic list? – dcaswell Aug 25 '13 at 17:12
  • And how/why was the other question not useful? – H H Aug 25 '13 at 17:14
  • As a side note, .NET already has a [DayOfWeek](http://msdn.microsoft.com/en-us/library/system.dayofweek.aspx) enumeration which you can use if you're not doing anything else extra. It also starts at `Sunday = 0`. – keyboardP Aug 25 '13 at 17:16
  • Are you saying you have a list of days a user can access and you want to see it the enum the host provides is in it? – Tony Hopkinson Aug 25 '13 at 17:17
  • Ye irani az jense girl :-( – scripter May 22 '14 at 12:16

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,183
  • 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