我希望按以下格式获取特定年份的List<string>
天数列表:dd.MM.yyyy
public List<string> GetDays(int year)
{
List<string> lst = new List<string>();
foreach-day-in-year // TO DO iterate days from given year
{
string day="";
// TO DO iterate all days
lst.Add(day);
}
return lst;
}
答案 0 :(得分:2)
public IList<string> GetDays(int year)
{
var days = new List<string>();
var start = new DateTime(year, 1, 1);
while (start.Year == year)
{
days.Add(start.ToString("dd.MM.yyyy"));
start = start.AddDays(1);
}
return days;
}