2

I wonder if there is a difference between writing list declare with or without parentheses.

I tested both :

List<int> ListWithParentheses = new List<int>() { 1, 2, 3 };
List<int> ListWithoutParentheses = new List<int> { 1, 2, 3 };

And I got the sames results.

A.Pissicat
  • 3,023
  • 4
  • 38
  • 93

1 Answers1

3

It is possible to use parameters, as in

List<int> ListWithParentheses = new List<int>(capacity: 100) { 1, 2, 3 };

and then you absolutely need the (). When you have 0 parameters, you can use () or by a special rule omit them all together.

bommelding
  • 2,969
  • 9
  • 14