I would like to know what is the difference between initializing a static member inline as in:
class Foo
{
private static Bar bar_ = new Bar();
}
or initializing it inside the static constructor as in:
class Foo
{
static Foo()
{
bar_ = new Bar();
}
private static Bar bar_;
}
Best Solution
If you have a static constructor in your type, it alters type initialization due to the beforefieldinit flag no longer being applied.
It also affects initialization order - variable initializers are all executed before the static constructor.
That's about it as far as I know though.