in my Class I have a static dictionary of strings object which contains a big number of Items (it reads from a file and initial them) I wrote a static constructor to do so and it takes a few seconds, but I want to do it once to be faster, since I’m doing it in ASP.Net and I want my website not to have this overhead what should I do? if this constructor runs for each object then I was thinking of some method instead but I guess I have to run this method in each page of website which user runs, so I think again it would be the same, am I right?
what’s your solution for initialization a big set of variables only once? thanks
in my Class I have a static dictionary of strings object which contains a
Share
It runs once for the type, per
AppDomain. Not once per instance. From the C# 4 spec, section 10.12:Note the part about it being per closed class. So if you have a generic type
Foo<T>, thenFoo<string>is a separate type toFoo<object>(etc), will have separate static fields, and will have its static constructor invoked separately.