Help Re: DateTime and DayofWeek - Increasing DayofWeek Value
-
So I have a dictionary with DayofWeek and Int. I need to find out how to populate the Dictionary then with the Days and and integer increase. for example right now I create a dictionary:
Dictionary<int,DayOfWeek> dicFindDates = new Dictionary<int,DayOfWeek>();
then I get the day of week it is for example today is "Thursday"DayOfWeek dowStartDay = (DayOfWeek)Enum.ToObject(typeof(DayOfWeek), (int)S.StartOfWeek);
then I add to the dictionarydicFindDates.Add(0,DayofWeek)
while (i<6)
{
dicFindDates.Add(i++,DayofWeek <------ ++????)
}so that I get(and can change according to date): 0, Thursday 1, Friday 2, Saturday 3, Sunday 4, Monday 5, Tuesday 6, Wednesday
-
So I have a dictionary with DayofWeek and Int. I need to find out how to populate the Dictionary then with the Days and and integer increase. for example right now I create a dictionary:
Dictionary<int,DayOfWeek> dicFindDates = new Dictionary<int,DayOfWeek>();
then I get the day of week it is for example today is "Thursday"DayOfWeek dowStartDay = (DayOfWeek)Enum.ToObject(typeof(DayOfWeek), (int)S.StartOfWeek);
then I add to the dictionarydicFindDates.Add(0,DayofWeek)
while (i<6)
{
dicFindDates.Add(i++,DayofWeek <------ ++????)
}so that I get(and can change according to date): 0, Thursday 1, Friday 2, Saturday 3, Sunday 4, Monday 5, Tuesday 6, Wednesday
Hi,
(DayOfWeek)i
should do it. [Added] Which also implies you don't really need a dictionary at all... [/Added] BTW: I recommend you use a for loop, rather than an auto-increment in the middle of a statement. And you can handle all seven days in the same way, no need to treat 0 separately. FWIW: I have some goodies about DateTime in this article[^]. :)Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
modified on Thursday, May 20, 2010 2:41 PM