2 ways of list making in c# [duplicate]

The two types you are referring to are:

  1. A type of Collection called a List, which would be defined as List aList = new List {"first" , "second"}
  2. An array, defined as string[ ] aList = {"first", "second"}

An array is a fixed-length, i.e. you typically define it saying it will contain a set number of Strings. A List, by contrast, will keep growing as you add elements (in the background, it stores the data in a dynamic array (i.e. one that grows and shrinks with the List).

There are a lot of other collections you can use too, a List isn’t the only one; and it depends how you want to represent your data.

Have a look at the Microsoft Documentation for Selecting a Collection class

Leave a Comment