Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a string array is null?

Tags:

vb.net

I modified a workflow in TFS template, in the head of this workflow I initialized an array of string named NextChainBuildDefinition. After a few steps, I tried to check if this array is null or not.

I did this way:

String.IsNullOrEmpty(CStr(NextChainBuildDefinition.Count))

After this I see error: Exception Message: Value cannot be null. Therefore NextChainBuildDefinition is null, and in that step it throws an exception.

How do I check if this string array is null?

like image 868
Maxim Petrov Avatar asked Oct 26 '25 21:10

Maxim Petrov


1 Answers

You need to check if the array itself is null or empty - your current code is checking if the string conversion of the number of elements in the array is empty - this isn't going to work at all.

Instead, you need to do a two step check - both for if the array itself is null, and if not, if it's empty:

If (NextChainBuildDefinition IsNot Nothing AndAlso NextChainBuildDefinition.Count > 0) Then
  'Array has contents
Else
  'Array is null or empty
End if
like image 176
James Thorpe Avatar answered Oct 29 '25 19:10

James Thorpe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!