2

I am new to Visual Basic, and I need help.

I have previously used Python where you simply create a list of items by simply doing:

list = [item1, item2]

But I have no idea how I can do this in Visual Basic.

Please can someone help me to simply create a list, like you can in Python, but in Visual Basic?

Laura White
  • 188
  • 2
  • 9
Fridge Thrower
  • 95
  • 1
  • 1
  • 7
  • https://learn.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/arrays/ – user94559 Sep 20 '17 at 12:43
  • 5
    Are search engines disabled in your locale? https://www.google.co.uk/search?q=VB.NET+List&oq=VB.NET+List&aqs=chrome..69i57j69i58j5j69i65l2j69i60.2208j0j7&sourceid=chrome&ie=UTF-8 returns, among other things, https://www.dotnetperls.com/list-vbnet which has some really very clear examples. Equally you could use arrays if you want a simpler structure. Did you research or try _anything_ before posting? – ADyson Sep 20 '17 at 12:43
  • Great @ADyson, I love this page! :-) – muffi Sep 20 '17 at 12:45

3 Answers3

5
dim list as item() = {item1, item2}

The () next to item signify that it is an array.

A working example of an integer list:

Dim list As Integer() = {1, 2, 3}

These lists are refered to as "arrays" though.

If you want an actual list, you can do:

Dim list As New List(Of Integer)({1,2,3})

This one allows you to access .Add and .AddRange, and does not hold a static capacity.

Sasha
  • 1,674
  • 1
  • 16
  • 23
1
  Dim arraylist As New ArrayList
  arraylist.Add("item")

You can use this. It's a dynamic list

0

A list in Python would essentially be an Array in Visual Basic.

You would do this by saying Dim list(x) As Integer and then adding either the size of the list (in the parenthesis) or using a ReDim statement to create a dynamic array if you do not know what the initial size of the array is going to be.

Plaguedriver
  • 75
  • 1
  • 14