I have a program which has to do a lot of lookup.
there are multiple threads running in parallel and all of these threads have to do a lookup on the same list of words.

Currently i'm storing the list of words in a dictionary in each of the threads.

Is there some way i can use a static class which contains the list of all the words so that all the threads can just call a method of this static class and the class returns the result based on lookup.

I want to to this cos i don't want multiple copies of the same data on my memory.

Any suggestions...

6 Years
Discussion Span
Last Post by Momerath

I would also like to know the following.

If i have a static class in my application, does the class get instantiated as soon as the application is started. If so , can i write a static constructor which will load the lookup lists/dictionaries ?


Yes you can, just declare the class as static and all the methods/properties as static.

A static class is instantiated when the system decides it wants to do it but always before your first use of the class. You don't have to worry about when that happens, it just works (like magic :)).

And yes, you can have a static constructor. You can read about them here

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.