What is difference between new in a constructor and new in a member declaration?
c#, constructor, member
Solution
They're pretty much equivalent (any differences in terms of performance and memory usage are negligible). The only real difference is that when you do:
private List<string>name = new List<string>();
...the assignment always happens no matter what constructor is used to create an instance of the object. When you do the assignment within a constructor, then it only happens when that specific constructor is used.
So if you have multiple constructors but you always want to initialize `name` exactly the same way, it is a bit shorter to use the first form than to explicitly initialize it in each constructor.
As a general rule, however, I prefer initializing fields in the constructor implementations, even if it does make the code more verbose in some cases.
Problem
What is the difference between `new` in a constructor and `new` in a member declaration? Example ``` public class PspGame { private List<string>name = new List<string>(); private List<string>_value; public PspGame() { _value = new List<string>(); } } ``` What is the best way to do it and are there any performance issues?