Protip: comparing null to any integer always returns false, which is awesome with the safe navigation operator in C# 6

This is perfectly safe:

private static char GetLastElement(obj[] myArray) { if (myArray?.Length > 0) { return myArray[myArray.Length -1]; } return null; } 

by Pharylon via /r/csharp

Leave a Reply