C# Field Naming Guidelines?

后端 未结 17 1311
天命终不由人
天命终不由人 2020-12-02 16:37

I am going to be working on a bit of C# code on my own but I want to make sure that I follow the most widely accepted naming conventions in case I want to bring on other dev

17条回答
  •  心在旅途
    2020-12-02 17:12

    In our shop, we started our first C# project using Microsoft's suggested guideline for private members, i.e.

    camelCaseFieldName
    

    But we soon ran into confusion between private members and parameters, and switched to

    _camelCaseFieldName
    

    which has worked much better for us.

    A private member usually has a state that persists outside of a method call - the leading underscore tends to remind you of that.

    Also note that using AutoVariable syntax for properties can minimize the need for private backing fields, i.e.

    public int PascalCaseFieldName { get; set;}
    

    For a nice concise set of standards that (mostly) follow the MS guidelines, check out net-naming-conventions-and-programming-standards---best-practices

提交回复
热议问题