Naming Convention in c# [closed]

Microsoft has an excellent set of guidelines on class library design, including a section on naming. In short (examples in parentheses):

  • Classes/Structs: PascalCase (WebRequest)
  • Interfaces: PascalCase with I prefix (IDisposable)
  • Methods: PascalCase (ToUpper)
  • Properties: PascalCase (Length)
  • Events: PascalCase (Click)
  • Namespaces: PascalCase (System.Collections; unusual to have two words in one part though)
  • Non-constant variables including parameters: camelCased (keySelector)
  • Constants: PascalCase (Int32.MaxValue)
  • Enums: PascalCase, singular for non-flags and plural for flags (HttpStatusCode, BindingFlags)
  • Attributes: PascalCase with “Attribute” suffix (ThreadStaticAttribute)

Private names are up to you, but I tend to follow the same conventions as for everything else. Hungarian notation (in the style of Win32) is discouraged, although many places use “m_” or “_” as a prefix for instance variables.

Leave a Comment