user5346812
user5346812

Reputation:

Is there a difference in these declarations?

Both of these are declaring Jagged Lists correct?

//Declare 'Jagged' List
//Version 1
private List<string>[] fieldInfoArray = new List<string>[7];

//Version 2
private List<string>[][] fieldInfoArray = new List<string>[7][];

There is no difference between these two declarations right? They are both essentially doing the same thing correct? Declaring a Jagged List?

Upvotes: 3

Views: 81

Answers (2)

displayName
displayName

Reputation: 14389

  • Both declare arrays. When you will try to access the elements of either array, you will be returned List<string>.
  • First one is a 1-D array of size 7. All the 7 elements are List<string>s.
  • The second array is also a 1-D array of size 7 but each of those 7 elements is another "1-D array of List<string>" (and not just "List<string>").

Upvotes: 2

mattkgross
mattkgross

Reputation: 801

private List<string>[] fieldInfoArray = new List<string>[7];

This is declaring an array, of size 7, of List<string>.

private List<string>[][] fieldInfoArray = new List<string>[7][];

This is declaring a two dimensional array of List<string>, containing 7 rows of List<string> arrays who are yet to be initialized/allocated.

Upvotes: 0

Related Questions