Created
May 19, 2014 17:00
-
-
Save jesslilly/889585860bfe4dc1650c to your computer and use it in GitHub Desktop.
Different ways of comparing dates in C#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
public class Program | |
{ | |
public static void Main() | |
{ | |
DateTime a = DateTime.Now; | |
DateTime z = DateTime.Parse("2014-06-01 00:00:00"); | |
//var list = new DateTime[1]; | |
//list[0] = (z); | |
var list = new List<DateTime>(); | |
list.Add(z); | |
var expired = list.Any<DateTime>(d => d < a); | |
Console.WriteLine("a " + a); | |
Console.WriteLine("z " + z); | |
Console.WriteLine("expired " + expired); | |
Console.WriteLine("expired " + (z.CompareTo(a) < 0)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment