Skip to content

Instantly share code, notes, and snippets.

@AmirOfir
Created July 29, 2018 07:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AmirOfir/1a5482a5ebd184644e0b4c2131743a2b to your computer and use it in GitHub Desktop.
Save AmirOfir/1a5482a5ebd184644e0b4c2131743a2b to your computer and use it in GitHub Desktop.
DateRange with nullable optional parameters - c#
public DateTime? From { get; set; }
public DateTime? To { get; set; }
readonly DateTime minFrom = new DateTime(2000, 1, 1);
readonly DateTime maxTo = new DateTime(2100, 1, 1);
public DateTime SafeFrom() =>
From.GetValueOrDefault(To.GetValueOrDefault(minFrom));
public DateTime SafeTo() =>
To.GetValueOrDefault(From.GetValueOrDefault(maxTo));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment