Hmm ... I'm surprised that compiles (this, I checked). I do not know any guarantees that will make it safe. Use a static constructor ...
Edit: I accept (see best answer above ) that it will work; but my idea with the code is to make it as simple and obvious as possible. If it is not obvious that it will work (and cannot be, if you need to ask), then do not write it this way ...
In particular, problems related to field order:
- it may break if you move the code (which I often do)
- it may break if you split the code into
partial classes
My advice remains: use a static constructor for this scenario.
Marc Gravell Sep 29 '09 at 20:27 2009-09-29 20:27
source share