In C# 3.0 you can assign null to int? type (in CLR int? is a struct):
int? a = null;
but when you define a custom struct:
struct MyStruct
{
}
there's an error during the compilation of this code:
MyStruct a = null;
The error is as follows:
Cannot convert null to 'Example.MyStruct' because it is a non-nullable value type
While int? is a struct in CLR it is somehow counterintuitive that we can assign null to it. I suppose that null is implicitly casted or boxed to a certian int? value that represents the null value. How is it done precisely? How can I extend MyStruct in such a way that it would be possible to execute the line:
MyStruct a = null;