How to check if a string array is null?

19,397

Solution 1

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

Solution 2

Why not just test ubound() of the array? old question, i know.

Share:
19,397

Related videos on Youtube

Maxim Petrov
Author by

Maxim Petrov

Updated on October 09, 2022

Comments

  • Maxim Petrov
    Maxim Petrov over 1 year

    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?

  • Maxim Petrov
    Maxim Petrov over 9 years
    Thanks. That is what I need.