Skip to content

Instantly share code, notes, and snippets.

@dfmartin
Created August 27, 2015 04:22
Show Gist options
  • Save dfmartin/cd2ce4ed763b09f8f1f0 to your computer and use it in GitHub Desktop.
Save dfmartin/cd2ce4ed763b09f8f1f0 to your computer and use it in GitHub Desktop.
var x = People[0].Address.City;
// oops! Null reference exception. Need to replace with. . .
string x = string.Empty;
if(People != null) {
var p = People[0];
if (p != null) {
var a = p.Address;
if (a != null) {
x = a.City;
}
}
}
// whew! Did all my braces line up?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment