Click here to Skip to main content
15,900,258 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I would like to sort month as displayed in calender using C#.net
like, January,February,March,April.........December

can anyone help
Posted
Updated 16-Sep-12 21:36pm
v2

1 solution

Try this example

C#
static void Main()
{
var list = new List<datetime>();
list.Add(new DateTime(2010, 5, 5));
list.Add(new DateTime(2010, 10, 20));
list.Add(new DateTime(2010, 1, 4));
list.Add(new DateTime(2010, 6, 19));

Display(SortMonthAscending(list), "SortMonthAscending");
}

static List<DateTime> SortMonthAscending(List<DateTime> list)
{
    list.Sort((a, b) => a.Month.CompareTo(b.Month));
    return list;
}

static void Display(List<datetime> list, string message)
{
Console.WriteLine(message);
foreach (var datetime in list)
{
    Console.WriteLine(datetime);
}
Console.WriteLine();
}</datetime></datetime>


This should help you sorting your dates.


Cheers
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900