简体   繁体   中英

Pascal Case in C# properties

Which one do you choose and why:

public class User
{
    public long UserID { get; set; }
}

public class User
{
    public long UserId { get; set; }
}

And also as parameters:

public void DoSomething(long userId) { }
public void DoSomething(long userID) { }

The conventions make it very clear to choose UserId and userId respectively (emphasis mine):

The two abbreviations that can be used in identifiers are ID and OK. In Pascal-cased identifiers they should appear as Id, and Ok. If used as the first word in a camel-cased identifier, they should appear as id and ok, respectively.

For Id, its short for Identifier, and not an acronym; It makes sense to make it lower case after the first letter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM