au jetzt hab ich doch ein Problem mit deiner Lösung:
2 Klassenvariablen:
private static DateTime tempSchoolYearStart;
private static DateTime tempSchoolYearEnd;
private List<DateTime> schoolyearList;
deine forschleife abgeändert von mir:
C#-Quelltext
1: 2: 3: 4: 5: 6: 7:
| private void ReadAllDays() { for (tempSchoolYearStart; tempSchoolYearStart <= tempSchoolYearEnd; tempSchoolYearStart.AddDays(1)) { schoolyearList.Add(tempSchoolYearStart); } } |
nun bekomme ich 1 Fehler: die Werte-Initialisierung der For-Schleife wie mache ich das mit dem Datum?
Moderiert von
Christian S.: C#-Tags hinzugefügt
also jetzt hätte ich noch 2 Lösungen:
C#-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9:
| private void ReadAllDays() { DateTime tmpDate = tempSchoolYearStart; do { schoolyearList.Add(tmpDate); tmpDate = tmpDate.AddDays(1); } while (tmpDate <= tempSchoolYearEnd); } |
oder eigentlicher aktueller C#2.0:
C#-Quelltext
1: 2: 3: 4: 5: 6: 7: 8:
| IEnumerable<DateTime> GetDateRange(DateTime StartingDate, DateTime EndingDate) { while (StartingDate <= EndingDate) { yield return StartingDate; StartingDate = StartingDate.AddDays(1); } } |
was sollte man nun benutzen?