Top "Static-constructor" questions

A static constructor is used to initialize any static data, or to perform a particular action that needs to be performed once only.

What's the best way to ensure a base class's static constructor is called?

The documentation on static constructors in C# says: A static constructor is used to initialize any static data, or to …

c# .net inheritance static-constructor
Creating a singleton ChannelFactory<T> and reusing for client connections

In our SharePoint/ASP.NET environment we have a series of data retriever classes that all derive from a common …

wcf singleton thread-safety channelfactory static-constructor
Public constructor and static constructor

I am reading a code in C# that uses two constructors. One is static and the other is public. What …

c# static-constructor
How does a static constructor work?

namespace MyNameSpace { static class MyClass { static MyClass() { //Authentication process.. User needs to enter password } public static void MyMethod() { //Depends on …

c# c#-4.0 static-constructor
Why isn't the static constructor from my base class called?

Lets say I have 2 classes: public abstract class Foo { static Foo() { print("4"); } } public class Bar : Foo { static Bar() { print("2"); } static …

c# static-constructor
C# Instance Constructor vs Static Constructor

What are the differences between the two? I've only used one kind of constructor and I believe it's the static …

c# constructor static-constructor
What is the rationale for not having static constructor in C++?

What is the rationale for not having static constructor in C++? If it were allowed, we would be initializing all …

c++ constructor language-design language-features static-constructor
Type initializer (static constructor) exception handling

I'm writing a WCF service in C#. Initially my implementation had a static constructor to do some one-time initialization, but …

c# .net exception static-constructor
Assigning to static readonly field of base class

public class ClassA { public static readonly string processName; } public class ClassB : ClassA { static ClassB() { processName = "MyProcess.exe"; } } I am getting …

c# static readonly static-constructor