Verify That An Array Is Valid

Here is some simple code to validate that an array is valid. Before trying to use an array, you should always validate it with this code first.

  Public Shared Function IsValidArray(ByVal array As Array) As Boolean

      Dim valid As Boolean = False

 

      If array Is Nothing Then

        Throw New ArgumentNullException(“array”)

      End If

 

      If (array IsNot Nothing) AndAlso (array.Length > 0) Then

        valid = True

      End If

 

      Return valid

 

  End Function

Tip By: David McCater

This code can be found in the open source dotNetTips.Utility assembly

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s