Is it possible to have a private setter in base class set from derived class without being public?

c#, getter-setter

Solution

Why don't you use `protected`?

public string MyProperty { get; protected set; }

protected (C# Reference)

A protected member is accessible within its class and by derived class instances.

Problem

Is it possible to give private access to a base class setter and only have it available from the inheriting classes, in the same way as the protected keyword works? ``` public class MyDerivedClass : MyBaseClass { public MyDerivedClass() { // Want to allow MyProperty to be set from this class but not // set publically public MyProperty = "abc"; } } public class MyBaseClass { public string MyProperty { get; private set; } } ```

Original source