Skip to content

Instantly share code, notes, and snippets.

@angelovstanton
Created September 6, 2015 10:03
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 angelovstanton/1c8eb69c230683ea6d7f to your computer and use it in GitHub Desktop.
Save angelovstanton/1c8eb69c230683ea6d7f to your computer and use it in GitHub Desktop.
float? yourSingle = -1.0f;
Console.WriteLine(yourSingle.GetValueOrDefault());
yourSingle = null;
Console.WriteLine(yourSingle.GetValueOrDefault());
// assign different default value
Console.WriteLine(yourSingle.GetValueOrDefault(-2.4f));
// returns the same result as the above statement
Console.WriteLine(yourSingle ?? -2.4f);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment