I'm wondering if theres a method to determine whether a certain range of array elements is empty or not. for example, if the array was initialized with 10 elements having the values "", then if data was later assigned to elements 5, 7, 9; could i test if elements 0-3 were empty, or rather contained an empty string ""?
array.Skip(startIndex).Take(count).All(x => string.IsNullOrEmpty(x));
So, if you are trying to check elements 0-3:
array.Skip(0).Take(4).All(x => string.IsNullOrEmpty(x));
For clarity, I left Skip
in there.
Edit: made it Take(4)
instead of 3 as per Jonathan's comment in the other answer (and now Guffa's comment in mine. ;) ).
Edit 2: According to comments below, the OP wanted to see if any of the elements matched:
array.Skip(0).Take(4).Any(x => string.IsNullOrEmpty(x));
So changed All
to Any
.
bool is0to3empty = myArrayOfString.Skip(0).Take(4).All(i => string.IsNullOrEmpty(i));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With