Compile time Error
the accessibility modifier of the set accessor must be more
restrictive than the property or indexer
during a scenerio like
private string TestString { get; private set; }
Why does this cause a compilation error? I understand more restrictive. Still, this shouldn’t cause any real problems. It’s an unecessary modification rather than a build killing issue. Why kill the build rather than toss up a warning?
If anything, the error message might be better read as “Redundant code found” or something to the like since:
private string TestString { get; private set; }is really the same as:
private string TestString { get; set; }But, because the compiler enforces the rule, it does make sense that you get it since
private, of course, can not be more restricted than itself.