Results 1 to 3 of 3

Thread: array size check

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2005
    Posts
    1

    array size check

    How do I check the size of an array? I want a condition where BlockList() has nothing in it.



    Dim BlockList() As String


    If BlockList size is 0 Then
    end if

  2. #2
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: array size check

    If BlockList.Length =0 Then
    Use "is" for reference types only
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: array size check

    Be aware that, while the Length property is a value type, the array itself is a reference type. This code:
    Code:
            Dim myArray() As String
    
            If myArray.Length = 0 Then
                MessageBox.Show("No elements.")
            End If
    will throw an exception because no Array object has been created. To create an array with no elements, use this code:
    Code:
    Dim myArray(-1) As String
    or
    Code:
    Dim myArray() As String = New String(-1) {}
    or
    Code:
    Dim myArray() As String = {}
    The array variable is a null reference until you either specify the upper bound of each dimension or assign an existing array object to it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width