c# - Is a static variable shared across all instance? -


in public class, have private static dictionary. since dictionary static, mean shared across other instance of same object (see example below).

public class tax {     private static dictionary<string, double> taxbrakets = new dictionary<string, double>(stringcomparer.ordinalignorecase)     {         { "individual",   0.18 },         { "business",     0.20 },         { "other",        0.22 },     };      public string type { get; set; }     public double computetax(string type, double d)     {         return d * taxbrakets[this.type];     } } 

is acceptable use dictionary in way (as static variable)?

your static variable taxbrakets not associated instance. this.taxbrakets not compile. occurrences of taxbrakets refer same dictionary. in general, it's totally acceptable use static dictionaries. particular use seems little funny though, i'd need see more code suggest changes.


Comments

Popular posts from this blog

Cursor error with postgresql, pgpool and php -

delphi - ESC/P programming! -

c++ - error: use of deleted function -