+ 1
What is the meaning of this constructor? And why is it a constructor?
public List(int capacity=defaultCapacity) { items = new T [capacity] ; }
1 Réponse
+ 12
A constructor was used the perform initial setup or logic need to be performed when the object was created/instantiated and have the same name as its class.
Just like methods, constructor can be overloaded with different parameters like the example you've given — It use an optional parameter to setup the object.
Therefore the following statements will trigger the constructor above:-
var listA = new List();
var listB = new List(123);
P/S: This is an oversimplification as the defualt implementation of List in C# include generics.