i studied .Net and asked myself a question
how to better initialize List in Class
public class CollectionTest
{
public List<int> list1 { get; set; } // first way
public List<int> list2 = new List<int>(); // second way
public CollectionTest() {
list1 = new List<int>();
}
}
what is better and why
Maybe I didn’t formulate this question correctly, but Google didn’t find an answer to it. So I’m probably repeating it, but I hope for your understanding.
New contributor
HQWZI is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1