dotnet / docs

This repository contains .NET Documentation.
https://learn.microsoft.com/dotnet
Creative Commons Attribution 4.0 International
4.17k stars 5.83k forks source link

Add example for short { get; private set; } #28755

Closed twoco closed 1 year ago

twoco commented 2 years ago

https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/restricting-accessor-accessibility

Add example:

public string Name { get; private set; } 

Good to know. It's equal (not exact) shorthand like:

private string _name = "Hello";

public string Name
{
    get
    {
        return _name;
    }
    private set
    {
        _name = value;
    }
}

(a half novel.)

But add some notes if exists.


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

BillWagner commented 2 years ago

Thanks for noting this @twoco

In general, we update the code in the samples to make use of newer C# features. This must have been missed in some updates. We'll update that on our next regular update.