c# - Referring to private singleton property within singleton class -


in case of singleton class seen below, proper way initialize mylist? refer directly field mylist (option 1) or instance.mylist (option 2)? what's best practice here? gut says go through instance, i'm second-guessing myself , cannot find definitive answer anywhere.

public class foo {     private readonly static lazy<foo> _instance =         new lazy<foo>(() => new foo());      private list<string> mylist;      public static foo instance     {         { return _instance.value; }     }      private foo()     {         mylist = new list<string> {"a","b","c"}; //option 1          instance.mylist = new list<string> {"a","b","c"};  //option 2     } } 

to start with, either way fine. being said, prefer option doesn't use "instance" identifier. concept of instance belongs code outside of singleton class. inside class, fact singleton should known. thus, specifying instance identifier redundant.


Comments