ALalavi ALalavi - 1 year ago 62
Vb.net Question

hard-code a numeric table in VB.NET

I have a numeric table (10 rows, 5 columns) that i want to have in my code. It means i don't want to read it from external source in my code.

What is the best way to hard-code a table in VB.NET? Arrays, List, or anything else ? The correct way should have as little code as possible for adding numeric data.

I already tried this code to escape from defining each element in one line, but it doesn't work.

Dim b(2, 2) As Integer
b(0) = {5, 2}, {4, 3}

Answer Source

1) List of lists - pretty simple for both adding and reading data

Dim lst As New List(Of Int16) From {11,222,33}

2) 3D Array - you needt to handle the size of array correctly. In this case, where you have a fixed set of data it is easy too.

3) Structure - easy data access, but a bit complicated in setting up

Dim arr = {{1, 2}, {3, 4}}
  • credits to jmcilhinney comments bellow

Here is a post both with array and structure answer.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download