Declaring arrays in VB.NET

Posted by Marcus Hammarberg on October 5, 2007
OK - this is driving me mad. Arrays in VB.NET really, really annoys me. Here is a short list on how to work with arrays, in my example an array of strings.

  1. Declaring an new empty array:
    Dim arr() as String = {}
    or (this is where the pain begins...why is there a choice?)
    Dim arr as String() = {}

  2. Declaring an array with three elements:
    Dim arr(2) as String

  3. Declaring an array with two elements and initializing the values
    Dim arr as String() = {"Element 1", "Element 2"}

So - again the pain of VB.NET comes from the urge to want to help us all the time. Why, oh why, are there several ways of doing one thing?

I will sure get back to this post a lot because i forget how this is done every time - much thanks to the "helpfulness" of VB.NET

If you liked this post ... here's more for you:

Published by Marcus Hammarberg on Last updated