, - () . February 29th, 2000 February 29th, 2013.
:
var ordered = from dt in dtlist
orderby dt.Month, dt.Day
select dt;
, ( ):
private static bool IsBeforeNow(DateTime now, DateTime dateTime)
{
return dateTime.Month < now.Month
|| (dateTime.Month == now.Month && dateTime.Day < now.Day);
}
, / , , :
var now = DateTime.Now;
var afterNow = ordered.SkipWhile(dt => IsBeforeNow(now, dt));
var beforeNow = ordered.TakeWhile(dt => IsBeforeNow(now, dt));
var birthdays = Enumerable.Concat(afterNow, beforeNow);
Rawling , : , afterNow , , beforeNow . IsBeforeNow , / concat. , LINQ :
var now = DateTime.Now;
var birthdays = from dt in dtlist
orderby IsBeforeNow(now, dt), dt.Month, dt.Day
select dt;
birthdays - . :
:
static void Main(string[] args)
{
var dtlist = new[]{
DateTime.Parse("25-July-1985"),
DateTime.Parse("31-Dec-1956"),
DateTime.Parse("21-Feb-1978"),
DateTime.Parse("18-Mar-2005")
};
var now = DateTime.Now;
var birthdays = from dt in dtlist
orderby IsBeforeNow(now, dt), dt.Month, dt.Day
select dt;
foreach (var dt in birthdays)
{
Console.WriteLine(dt.ToString("dd-MMM"));
}
Console.ReadLine();
}
private static bool IsBeforeNow(DateTime now, DateTime dateTime)
{
return dateTime.Month < now.Month
|| (dateTime.Month == now.Month && dateTime.Day < now.Day);
}
18-mrt
25-jul
31-dec
21-feb