Tuesday 15 March 2011

clr - Making C# 6 struct parameterless constructor unusable -


C # 6, allows the declaration of paramilitary constructors on strokes. Although they should be public and there are situations where other developers should be forced to use the parametric constructor, I am thinking that in the perspective of CLR, it will be fine that by throwing an exception, to make the parasailable constructor unusable , Then it will look like this:

  public infrastructure fu {public fu () {new invalid operation exp ( "This constructor is not supported."); } Public Foo (int I) {...}}  

You can do this Are there. Whether or not it is a good idea but subjective. (I will strongly discourage use of it, but clearly I can not do stop from doing so.)

If your goal is to ensure that no such situation Not where the object is created without calling the parameterized constructor, and that the field never left on its default values, it does not do this.

If you are asking if the CLR is going to crash and the world will enter the black hole because you < The exception is thrown from the constructor of code> struct , no, it is not going to be done

it is thrown away, and until it is caught, call stack Makes your way, like any other thrown exception.


No comments:

Post a Comment