Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

In C#, there are several ways to name elements depending on the type and purpose of the element.

  1. CamelCase: This is the most common naming convention used for naming variables, fields, and parameters. The first letter of the variable is lowercase, and the first letter of each subsequent word is capitalized.

Example: firstName, numberOfStudents, totalPrice

  1. PascalCase: This naming convention is used for naming classes, structures, and methods. The first letter of each word is capitalized, including the first word.

Example: CustomerOrder, GetTotalPrice, CalculateGrade

  1. underscore: This naming convention is used for private fields in classes. The name starts with an underscore followed by the camelCase name.

Example: _firstName, _numberOfStudents, _totalPrice

  1. ALL CAPS: This naming convention is used for naming constants. The name is in all caps, and each word is separated by an underscore.

Example: MAXSTUDENTS, PI, MINIMUMAGE

  1. Verb-Noun: This naming convention is used for naming methods. The name starts with a verb followed by a noun in PascalCase.

Example: GetTotalPrice, CalculateGrade, PrintReport

  1. Abbreviations: Abbreviations are used for long variable names, and the casing rule applies. If the abbreviation is three letters or less, it is written in all caps; otherwise, only the first letter is capitalized.

Example: IOStream, maxCount, avgScore.