I have a statement that compares the length of elements in all string arrays.
string[][] allMyArrays= new string[][] { myArray1, myArray2, myArray3 };
lengthMismatch = allMyArrays.GroupBy(x => x.Length).Count() > 1;
However, null exception hits if any of them are null.
How can I get result that lengthMismatch = false if
- Any, but not all arrays are null
- One or more array(s) length are not equal
You could use:
On this way you still differrentiate between an empty array and a null array. If all are null this is
falseas desired.You could also use an optimized way avoiding
GroupByon the whole array: