You restore your static field in the constructor of the class instance, which causes the dictionary variable to reload / re-establish. Initialize the static field either in the line where it is declared in the class
static Dictionary<string, int> y = new Dictionary<string, int>() {kvs};
OR
in static constructor
static Dictionary<string, int> y;
static myClass()
{
y = new Dictionary<string, int>() {kvs};
}
The static constructor of class initializers or static fields runs only once in their lives.
source
share