C.1. General naming conventions

The casing conventions for C# are shown in Table C.2

Table C.2. Casing conventions for C#
CategoryCasing
Local variablesCamel casing
Parameters passed into methods (considered local variables)Camel casing
All other identifiers (names of namespaces, classes, interfaces, all class members)Pascal casing

This implies that your method and field names should use Pascal casing, like your classes. In C#, camel casing should be reserved only for local variables. [2]

[2] This is very different from Java's naming conventions. Java advocates that all class and interface identifiers should use Pascal casing, and all other identifiers use camel casing. C# says that all identifiers should use Pascal casing, except for local variables which should use camel casing.

Table C.3 lists some common suffixes and prefixes that should be used in C#.

Table C.3. Special naming requirements for naming C# members
CategoryNaming comments
AttributesSuffix with Attribute
ExceptionsSuffix with Exception
EventsSuffix with Event
Event argumentsSuffix with EventArgs
Event handler delegateSuffix with EventHandler
InterfacesPrefix with I
Pointer variablesPrefix with p

Additional notes

  • Hungarian notation is to be avoided, even for method parameters.

  • All upper case casing is to be avoided, even for constants. Use Pascal casing for constants. [3]

    [3] I have noticed that some constants in sample C# codes in the MSDN documentation and VS.NEThelp files are being named using all upper case casing. However, it is clearly noted in the C# Language Specification itself about constants using the Pascal notation. As I have mentioned, conventions and guidelines are flexible, but I would recommend following the official language specification.

  • The only occasion when all upper case casing can be considered is when the whole name is an abbreviation. For example, instead of choosing Windows.Forms.UserInterface as a namespace, you can use Windows. Forms.UI since 'UI' is universally accepted as an abbreviation for user interface.

  • All other commonsense guidelines apply. For example, you should select meaningful names for identifiers and use abbreviations sparingly (or avoid them altogether). [4]

    [4] Commonsense guidelines are not listed here because people without commonsense won't make developers.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.12.50