Using New to create Object array in VB.NET

We can create new Object array on declaration.

 
            Dim objArray As Object() = New Object() {"value1", 2, True}
            msg("Upper bound of the 0 dimension: " + objArray.GetUpperBound(0).ToString())
            msg("Length : " + objArray.Length.ToString())
 

There is another syntax with little difference but has the same effect.

 
            Dim objArray() As Object = New Object() {"value1", 2, True}
 

Creating Object by assignment array elements

This way you have to specify the length of the array.

 
            Dim objArray2(2) As Object
            objArray2(0) = "value1"
            objArray2(1) = 2
            objArray2(2) = True
 

But if you write like this.

 
            Dim objArray2() As Object(2)
 

You will get error

 
Array bounds cannot appear in type specifiers