Skip to content

Static Code Blocks?

Matt Huggins

Asked Apr 1, 2006, 2:27 PM EST1 answer
Share
LinkedInX
I have a static Hashtable variable in a class that I would like to populate prior to any instance of the class being created. However, it seems like the earliest point at which I can populate the Hashtable is within the constructor.

I know Java allows a static code block...
Code
static {
   // code here
}
...this allows for static code to occur prior to any object being created from the class. Is something like this possible in C#?? If not, does anyone have any suggestions on how to work around this?

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Hi! I think you're searching for static constructors. public class Test { static Test() { ... } }
    0