Monday, January 12, 2015

Bonus: The ?. operator in C# 6.0 will make it that much easier to break the Law of Demeter!

var parakeet = me?.CollegeRoomate?.ExWife?.HouseCat?.StomachContents;
if (parakeet != null) {
   parakeet.Resuscitate();
}

 
 

Per this, thanks to the "safe navigation operator" usage herein, we no longer need to worry if any of the steps along the way resolve to null as they will just make our variable null instead of throwing a complier error. Now I may easily reach into the stomach of the cat of the ex-wife of my college roommate as though I deserve to have my hands in there!

No comments:

Post a Comment