const int IterationsPerDay = 2;
DateTimeOffset currentDate = DateTime.Now.Date;
int dayCount = 0;
for (int j = 0; j < ((IterationsPerDay * 30) / ClientsList.Count); j += IterationsPerDay)
{
for (int f = 0; f < IterationsPerDay; f++)
{
int iterationIndex = j + f;
if (iterationIndex < productsOfSameCategory.Count)
{
Client _client = new Client();
_client.Name = ClientsList[iterationIndex].Name;
_client.Date = currentDate;
VisitsList.Add(_client);
}
if (iterationIndex < productsOfSameCategory.Count)
{
Client _client = new Client();
_client.Name = ClientsList[iterationIndex-ClientsList.Count].Name;
_client.Date = currentDate;
VisitsList.Add(_client);
}
}
currentDate.AddDays(1);
}
VisitsList
应该会添加所有30个日期。每个日期应该有两个客户端,因此列表中应该有60个记录。
为什么循环只添加第一个日期??
答案 0 :(得分:2)
建议点击相同的帖子:DateTime is immutable
因为日期是结构类型,即值类型及其不可变,你需要这样做
currentDate = currentDate.AddDays(1);
//above line store new data to to your currentdate variable with olddate+1