Skip to content

Instantly share code, notes, and snippets.

@scottashipp
Created January 3, 2019 15:31
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 scottashipp/e14c7bc6400526c5449ca505df624140 to your computer and use it in GitHub Desktop.
Save scottashipp/e14c7bc6400526c5449ca505df624140 to your computer and use it in GitHub Desktop.
Use of Null-Conditional operator in C#
int? length = customers?.Length; // null if customers is null
Customer first = customers?[0]; // null if customers is null
int? count = customers?[0]?.Orders?.Count(); // null if customers, the first customer, or Orders is null
@scottashipp
Copy link
Author

This is from the C# documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment