Is there any C# naming convention for a variable used in a property?

后端 未结 12 1672
无人及你
无人及你 2021-01-31 07:26

Let\'s say, we have a variable, which we want named Fubar

Let\'s say that Fubar is a String!

That means, we would define F

12条回答
  •  无人及你
    2021-01-31 08:27

    I see a ton of outdated answers (and non-standard ways representing C#6), so this one's for 2020:

    // "fubar" works, too, but "_" prevents CaSe typo mistakes
    private string _fubar;
    public string Fubar
    {
        get => _fubar;
        set => _fubar = value;
    }
    
    // Read-only can just use lambda to skip all those shenannigans
    public string ReadOnlyFoo => "This is read-only!";
    

提交回复
热议问题