c# - Should I fill collections in ctor or private static method? -
if have collection object empty needs filled , going used class (say class foo), best filling in constructor?
something like:
list<string> strings = new list<string(); strings.add("sjsjhsj"); // on...
or should in static private ctor? state not being changed of containing class can static, right?
btw, if write this.name = name; or:
john.name = name; // instance method passing in john person object.
are these both known changing state , should not static? or instance?
if need collection want able change contents of without recompile, should use txt file or xml source. faster when using collections? txt file use readalllines(); , xml use nodenavigator (not sure of exact method/object names).
thanks
first, static constructors cannot public / private. exist.
if same instance of collection going shared amongst instances of owning class, can static.
static doesn't mean doesn't change state. can still change. difference static fields shared between instances of class, mutable operations on field need coordinated. if instances of class always use same data, make static.
whether text file or xml file faster depends on data.
Comments
Post a Comment