B
Berryl Hesh
The routines below work fine, but is there a more elegant way to do the
second one? It seems there would at least be a built-in function to return
the ordinal position of an element found.
Thanks for sharing - BH
----------------------------------------
/// <summary>Returns an array of the .Net <see cref="DayOfWeek"/>
enumeration, in order, starting on Sunday.</summary>
public static DayOfWeek[] DaysOfTheWeek() {
DayOfWeek[] result = { DayOfWeek.Sunday, DayOfWeek.Monday,
DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday,
DayOfWeek.Friday, DayOfWeek.Saturday };
return result;
}
/// <summary>Returns an array of the .Net <see cref="DayOfWeek"/>
enumeration, in order, starting on the passed <see
cref="DayOfWeek"/>.</summary>
public static DayOfWeek[] DaysOfTheWeek(DayOfWeek dayOfWeekToStartOn) {
var result = new DayOfWeek[7];
int start = 0;
for (int i = 0; i < 7; i++) {
if(DaysOfTheWeek().Equals(dayOfWeekToStartOn)) {
start = i;
break;
}
}
int count = start;
for (int i = 0; i < 7; i++) {
result = DaysOfTheWeek()[count];
if (count == 6 && start != 0)
count = 0;
else count++;
}
return result;
}
second one? It seems there would at least be a built-in function to return
the ordinal position of an element found.
Thanks for sharing - BH
----------------------------------------
/// <summary>Returns an array of the .Net <see cref="DayOfWeek"/>
enumeration, in order, starting on Sunday.</summary>
public static DayOfWeek[] DaysOfTheWeek() {
DayOfWeek[] result = { DayOfWeek.Sunday, DayOfWeek.Monday,
DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday,
DayOfWeek.Friday, DayOfWeek.Saturday };
return result;
}
/// <summary>Returns an array of the .Net <see cref="DayOfWeek"/>
enumeration, in order, starting on the passed <see
cref="DayOfWeek"/>.</summary>
public static DayOfWeek[] DaysOfTheWeek(DayOfWeek dayOfWeekToStartOn) {
var result = new DayOfWeek[7];
int start = 0;
for (int i = 0; i < 7; i++) {
if(DaysOfTheWeek().Equals(dayOfWeekToStartOn)) {
start = i;
break;
}
}
int count = start;
for (int i = 0; i < 7; i++) {
result = DaysOfTheWeek()[count];
if (count == 6 && start != 0)
count = 0;
else count++;
}
return result;
}