当前位置: 动力学知识库 > 问答 > 编程问答 >

vb.net - How to check if a string array is null?

问题描述:

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?

网友答案:

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
网友答案:

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

分享给朋友:
您可能感兴趣的文章:
随机阅读: