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

后端 未结 12 1688
无人及你
无人及你 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:09

    The c# way is

    private string _fubar;
    public string Fubar
    {
        get
        {
            return _fubar;
        }
        set
        {
            _fubar = value;
        }
    }
    

    However, if it's just a basic getter/setter with no extra logic, you can just write

    public string Fubar { get; set; }
    

    No need for a backing variable or anything.

提交回复
热议问题