Automatic Properties Weirdness


In my current project I was doing some 3.5 coding (at last!!!) and I found something really weird at first glance.

Let's say that you have a really simple struct in the "old 2.0 style", something like this:

With this code, we have the default constructor as it is a value type, so these lines are valid:

Let's get rid of some code using automatic (auto-implemented) properties:

Nice, you might think, but nay!! Compiler nags about "The 'this' object cannot be used before all of its fields are assigned to" and "Backing field for automatically implemented property 'S.P' must be fully assigned before control is returned to the caller. Consider calling the default constructor from a constructor initializer."
Doh!!! what if instead a value type we turn it into a reference type?

Now, it works, but we, of course, loose the default constructor and all the little niceties of value types (whatever they are).
But... I really want to make it work as a value type!!!

Ok, ok, here it goes: you have to explicitly call the default constructor:

Weird, isn't it? I guess that a peep into the guts of IL would tell us what is really happening. But... I am not there yet...


UPDATE: I'd better google before I post, as I am not by far the one and only who wrote about it... link, link and many more.

UPDATE": And if I had been using Resharper 4.0 I would have got earlier feedback as the engine warns about it,

share class