Is it possible to use a public init accessor and a private setter on the same property?
Currently I get error CS1007 "Property accessor already defined".
public record Stuff
{
public int MyProperty { get; init; private set; } // Error
public void SetMyProperty(int value) => MyProperty = value;
}
var stuff = new Stuff
{
MyProperty = 3, // Using the init accessor
};
stuff.SetMyProperty(4); // Using the private setter (indirectly)
My best guess would be to use a private member variable, a property for that variable with get and init accessors (not auto-implemented) and the setter member function. Can it be done more easily?