I want to check if my array is empty or null, and on base of which I want to create a condition for example.
if(array == EMPTY){ //do something }
I hope I'm clear what I am asking, just need to check if my array is empty?
regards
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.
To check if an array contains an empty string, call the includes() method passing it an empty string - includes('') . The includes method returns true if the provided value is contained in the array and false otherwise.
The array can be checked if it is empty by using the array. length property. This property returns the number of elements in the array. If the number is greater than 0, it evaluates to true.
To check if an given array is empty or not, we can use the built-in Array. Length property in C#. Alternatively, we can also use the Array. Length property to check if a array is null or empty in C#.
if (!array || !array.count){ ... }
That checks if array is not nil, and if not - check if it is not empty.
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