-
迭代时刻表中的日期
public class TimeTable
{
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public IEnumerable<DateTime> DateRange
{
get
{
for (DateTime day = StartDate; day <= EndDate; day = day.AddDays(1))
{
yield return day;
}
}
}
public TimeTable()
{
StartDate = DateTime.Now;
EndDate = DateTime.Now.AddDays(7);
}
}
foreach (var item in tt.DateRange)
{
}
-
迭代文件中的行
static IEnumerable<string> ReadLines(Func<TextReader> provider)
{
using (TextReader reader = provider())
{