dotnet/roslyn

static readonly autoimplemented property

Open

#16,647 opened on Jan 20, 2017

View on GitHub
 (4 comments) (2 reactions) (0 assignees)C# (4,257 forks)batch import
Area-CompilersBugConcept-Diagnostic Clarityhelp wanted

Repository metrics

Stars
 (20,414 stars)
PR merge metrics
 (Avg merge 6d 17h) (256 merged PRs in 30d)

Description

Why does the following code given an error during compilation? public class A { }

public class B
{
    private static A AF { get; }

    public B()
    {
        AF = new A();
    }
}

C# 6.0, .NET 4.5, VS2015 Update 3

Expected Behavior: This code should not give a compiler error

Actual Behavior: error CS0200: Property or indexer 'B.AF' cannot be assigned to -- it is read only

Contributor guide