linq - How to sort a date list order by ascending descending

c# linq example - sort date List order by ascending descending
sort-date-List-order-by-ascending-descending.aspx

<%@ Page Language="C#" AutoEventWireup="true"%>  
  
<!DOCTYPE html>  
<script runat="server">  
    protected void Button1_Click(object sender, System.EventArgs e)  
    {
        List<DateTime> holidays = new List<DateTime>();
        DateTime today = DateTime.Today;
        holidays.Add(today);
        holidays.Add(today.AddDays(5));
        holidays.Add(today.AddDays(1));
        holidays.Add(today.AddDays(7));
        holidays.Add(today.AddDays(3));

        Label1.Text = "holidays.....<br /> ";
        foreach (DateTime d in holidays)  
        {  
            Label1.Text += d.ToShortDateString() + "<br />";
        }

        var sortedholidays = holidays.OrderBy(x => x);
        Label1.Text += "<br />ascending sorted holidays.........<br />";
        foreach (DateTime d in sortedholidays)
        {
            Label1.Text += d.ToShortDateString() + "<br />";
        }

        var descendingholidays = holidays.OrderByDescending(x => x);
        Label1.Text += "<br />descending sorted holidays.........<br />";
        foreach (DateTime d in descendingholidays)
        {
            Label1.Text += d.ToShortDateString() + "<br />";
        }
    }  
</script>  
  
<html xmlns="http://www.w3.org/1999/xhtml">  
<head id="Head1" runat="server">  
    <title>c# linq example - sort date List order by ascending descending</title>  
</head>  
<body>  
    <form id="form1" runat="server">  
    <div>  
        <h2 style="color:DarkBlue; font-style:italic;">  
            c# example - sort date List order
            <br /> by ascending and descending
        </h2>  
        <hr width="550" align="left" color="LightBlue" />    
  
        <asp:Label   
            ID="Label1"   
            runat="server"  
            Font-Size="Large"  
            >  
        </asp:Label>  
        <br />
        <asp:Button   
            ID="Button1"   
            runat="server"   
            Text="sort date List"  
            OnClick="Button1_Click"  
            Height="40"  
            Font-Bold="true"  
            />  
    </div>  
    </form>  
</body>  
</html>
More c# linq examples