C# Vs. VB – Arrays….

Category : C#, VB.Net

I would just like to point out two areas where both C# and VB.Net beat the other one in the usage of arrays.

C# PRO:

You can redefine your array simply in C# by simply reinitializing the array:

//Declare array
int[ ] myInts = new int[20];
//Now reinitialize like this
myInts = new int[40];

In VB you have to reinitialize with the ReDim keyword

Dim myInts(20)
ReDim myInts(40)

Not a big deal but I give the better implementation to C# on this one…however.
===========================================

In VB.Net you can actually reinitialize an array AND MAINTAIN the data within the current array!
This is accomplished by using the ‘Preserve’ keyword. (this is not available in C#)

'Declare array
Dim myInts() As Integer = { 1,2,3,4 }
'Resize array and keep the data with the Preserve keyword
ReDim Preserve myInts(20)

Post a comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word