DCSIMG
How to name Private Methods in C#? - urig - Tidbits from a .net life

How to name Private Methods in C#?

Published 07 January 07 11:45 AM | urig

I'm having a debate (with myself mostly) concerning the proper way to name private methods in C# projects.

For some forgotten reason, I have been accustomed to use camel casing when naming private methods - as opposed to using Pascal casing for public methods. Example:

private int getBlockInfo(int memberID) {...}
public int GetBlockInfo(int memberID) {...}

For me this seems very comfortable for differentiating between private "secret" methods within a class and public methods that are visible outside. This is similar in my mind to using camel case for private members while using Pascal case for matching public properties.

private int memberID;

public int MemberID { get { return memberID; } set { memberID = value; } }

Still, feeling somewhat insecure concerning the origin of this habit of mine, I consulted the C#  "Naming Guidelines" document buried deep within the MSDN. To my surprise the "Method Naming Guidelines" sections ignored the issue of private vs public methods and instructed that all methods should be named in Pascal case.

There is not doubt in my mind that I should follow Microsoft naming guidelines at all times. And yet there's this nagging feeling that my current habit rises not from whim but from logic. I must've seen this convention somewhere and adopted it. Do any of you, my trusted readers, know where it came from?

Comments

# Peter said on August 13, 2008 11:54 PM:

Don't do it!!!  

If I see a statement in PascalCase such as

x=Price * z.

I can make an assumption that Price is a function.

If I see

x=price*z

It becomes less clear - is it a method or a value.

You only gain the knowledge the method is private - you're looking at the class anyway - you can see the method definition.

Refactoring becomes a pain.