Array Instantiation fails without providing initializer list

Trying to instantiate an array without an initialization list in .Net console app with latest Alpha.

This works -
Dim myIntArray() As Integer ’ Declare the array.
myIntArray = New Integer() {1, 2, 3, 4} ’ Instantiate the array.

This doesn’t with Type error “Int32” has no accessible constructors -

Dim IntArray() As Integer ' Declare the array.
IntArray = New Integer(3) ' Instantiate the array.

btw, .Net windows forms template continues with fail with no main method could be found.

Kind regards


1 Like

This bug is known and logged, waiting to be fixed.

This is also a known bug.

To work around at this moment, set in the application.myapp the option MySubMain to false, regenerate (right click on the file in the tree and click on Update Application.designer.vb) and provide your own Sub Main in the project.

1 Like

Never mind that workaround; I see that the application.myapp is missing on the template.

We will fix this in the coming week.

The bug in the windows forms template has been fixed - The new version on Friday will have this fix.

This bug is solved in the next alpha (released next Friday).

1 Like

Thanks Theo
Version initialising an array using upperbound of array is out by 1 as below :
Dim array1() As Integer = {32, 27, 64, 18, 95}
Console.WriteLine($“array1 length = {array1.Length}”)
Console.WriteLine($“Upperbound of array1 = {array1.GetUpperBound(0)}”)

// allocate 2nd array based on length of array1
Dim array2(array1.GetUpperBound(0)) As Integer
Console.WriteLine($“array2 length = {array2.Length}”)
Console.WriteLine($“Upperbound of array2 = {array2.GetUpperBound(0)}”)

Personally, I prefer the c#, oxygene method of specifying the array length rather than upper bound.

Also, the redim statememt fails with error No such static member

Kind regards


Redim is not fully implemented in 2525 yet.

Can you elaborate on what exactly is wrong?

This seems to behave correct affect:

The magic happens here.
array1 length = 5
Upperbound of array1 = 4

The VB way of declaring arrays has always been by specifying the upper bound, not the amount of elements.

Dim a(10) As String 'will create an array with 11 elements; 0 - 10

Will create an array with the elements a(0) to a(10)

The code:

Dim array1() As Integer = {32, 27, 64, 18, 95}
Console.WriteLine($“array1 length = {array1.Length}”)
Console.WriteLine($“Upperbound of array1 = {array1.GetUpperBound(0)}”)

Will print 5 and 4, because the length of the array is 5 elements (0-4) and the upperbound is 4

It is not a question of what you prefer, but a question of how the language works.
Just the VB way of doing things - see:

Edit: Just saw that Redim will be in the next version.

Output :
array1 length = 5
array1 upper bound = 4
array2 length = 4
array2 upper bound = 3

dim array2(array1.GetUpperBound(0)) should create a 5 integer array, not a 4 integer array.

Oxygene , C# method where you specify the length rather then the upper bound of the array better.


Good catch!

I filed a bug for this one.

1 Like

The bug has been fixed for the next version.

1 Like