int dateOffset = 0;
DateTimeOffset currentDate = DateTimeOffset.Now;
do
{
int sameDayCount = 0;
do
{
for (int record = 0; record < List.Count; record++)
{
Client client = new Client();
client.Name = List[record].Name;
client.Date = currentDate.AddDays(dateOffset);
List2.Add(client);
sameDayCount += 1;
}
} while (sameDayCount < 2);
dateOffset += 1;
} while (dateOffset < 30);
The above is the code I wrote thanks to my modest knowledge about and experience with the C# language. As you may expect it does not work as expected.
I need to populate the List2 with data from the List and additional element -DateTime.
Basically I want to schedule the names of clients for 30 days, two per day.
In the code i wrote I was hoping that do{} while (sameDayCount < 2); will work, but the sameDayCount += 1; is inside the for loop and do{} while actually waits for the for loop to finish (when it reaches record == List.Count). Anyway, the for loop will start over from record = 0 and I need it to go on from the last point it was left out when reached 2 records per day.
Any idea how I could resolve the problem?
So there are:
a List with finite number of records (Client's names)
30 days to be asssigned along with records
there must be two different records for each date
list with records must be re-read from the place it was left off
when the list is fully iterated(b=List.Count), it starts over again from b=0
the whole loop ends when 30th day is reached.
EDIT, how about if I put the do {} while ( sameDayCount < 2); within the for loop ??
Aucun commentaire:
Enregistrer un commentaire