Search code examples
c#readonlyautomatic-properties

Is there a way to make readonly (not just private) automatic properties?


Automatic properties let me replace this code:

private MyType myProperty;
public MyType MyProperty
{
    get { return myPropertyField; }
}

with this code:

public MyType MyProperty { get; private set; }

with a few changes here and there - but is there a way to replace this code:

private readonly MyType myProperty;
public MyType MyProperty
{
    get { return myPropertyField; }
}

with something similar?


Solution

  • No, but this idea is being tracked on Connect.