Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace ExampleOfOrderingByDate {
- class OrderingByDate{
- public static List<DateTime> myList;
- public static void Main(string[] args){
- /* Important: before invoking Reverse() on a list of dates, you must first invoke .Sort();
- .Sort sorts dates in ascending order, and then Reverse() reverses THAT ordering */
- PopulateTheList();
- Console.WriteLine(" The populated list 'myList' contains {0} DateTime item(s):", myList.Count);
- Console.Write(" Unsorted order: ");
- EnumerateTheList();
- Console.Write(" Sort ascending: ");
- myList.Sort();
- EnumerateTheList();
- Console.Write(" Sort descending: ");
- myList.Reverse();
- EnumerateTheList();
- }
- public static void EnumerateTheList(){
- foreach(DateTime dt in myList){
- Console.Write(dt.ToShortDateString() + " ");
- }
- Console.WriteLine();
- }
- public static void PopulateTheList(){
- myList = new List<DateTime>();
- myList.Add(DateTime.Parse("8/6/1937"));
- myList.Add(DateTime.Parse("6/15/1977"));
- myList.Add(DateTime.Parse("2/15/1947"));
- myList.Add(DateTime.Parse("3/15/1973"));
- myList.Add(DateTime.Parse("7/26/1971"));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement