Differences between arrays declarations

Asked

Viewed 155 times

2

What’s the difference between declaring a matrix like this:

 'C#
 string MinhaMatriz[] = []
 'VB
 Dim MinhaMatriz() As String = { }

and so:

 'C#
 string[] MinhaMatriz = []
 'VB
 Dim MinhaMatriz As String() = { }

or so:

 'C#
 System.Array<string> MinhaMatriz
 'VB
 Dim MinhaMatriz As System.Array(Of String)
  • 1

    Use the Gettype (Object inheritance) method and check for yourself. I believe that despite the various forms of statement, it does not change at all what the object is.

2 answers

3


Essentially the differences are syntactic. That is, it makes no difference to the program as you make the statement.

Note that in C# only the second form is valid in fact. In fact neither it, in the described form, after all does not exist the literal [] for array.

The third way doesn’t work exactly this way even in VB.NET. System.Array is not the same kind of array and it does not have a generic version as proposed. It has some tricks to simulate this but I think it is outside the scope of the question.

1

There is a difference between a list and an array. Its basic functions are virtually the same, but the Lists (List<T>) I, particularly, find more powerful and are more used.

// um array é declarado da seguinte forma:
string[] MeuArray = new string[5];



// Uma lista de objetos List<T> é declarado da seguinte forma
List<String> MinhaLista = new List<String>();
  • I don’t know this style of statement "string MinhaMatriz[] = []"
  • That’s not what I asked, the difference between statements of arrays, example: Dim teste() = { } and Dim teste As Object() = { }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.