An array is defined of assumed elements like I have array like String[] strArray = new String[50];.
Now from 50 elements only some elements are assigned and remaining are left null then I want the number of assigned elements.
Like here only 30 elements are assigned then I want that figure.
To check if an array is null, use equal to operator and check if array is equal to the value null. In the following example, we will initialize an integer array with null. And then use equal to comparison operator in an If Else statement to check if array is null. The array is empty.
This function counts all members, including nulls. An empty array (ARRAY[]) has a length of 0.
An array value can be non-empty, empty (cardinality zero), or null. The individual elements in the array can be null or not null.
Arrays in C don't have null slots. Using it as if it were an array of pointers to structs.
You can use Enumerable.Count:
string[] strArray = new string[50]; ... int result = strArray.Count(s => s != null);
This extension method iterates the array and counts the number of elements the specified predicate applies to.
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