Quick - do you know the difference between the two following classes?
class Test
{
static object o
= new object();
}
class Test
{
static object o;
static Test()
{
o = new object();
}
}
(example shamelessly stolen from here)
Says Jon:
The two classes are not, in fact, the same. They both have
type initializers - and the two type initializers are the same. However, the first
does not have a static constructor, whereas the second does. This means that the first
class can be marked as beforefieldinit and have its type initializer
invoked at any time before the first reference to a static field in it.
Somebody get this guy a blog!
- G

This
work is licensed under a
Creative
Commons License.