Menu
Coddy logo textTech

Naming Conventions

Part of the Fundamentals section of Coddy's C# journey — lesson 12 of 69.

Naming conventions are like the rules of the road for programmers. They help keep code organized and understandable.

Imagine if street signs were all random and inconsistent – it would be chaos! Similarly, without naming conventions, code can become messy and confusing.

In C#, following consistent naming conventions is crucial for writing clean, maintainable, and collaborative code. Here are some key conventions to keep in mind:

  • PascalCase: Use for class names, method names, and property names. Each word starts with a capital letter, e.g., MyClass, CalculateTotal, FirstName.
  • camelCase: Use for local variables and method parameters. The first word starts with a lowercase letter, and each subsequent word starts with a capital letter, e.g., myVariable, customerName, calculateTotal.
  • _underscorePrefix: Use for private fields (variables within a class). Start with an underscore followed by camelCase, e.g., _myPrivateField, _customerAge.
  • UPPER_CASE: Use for constants. All letters are uppercase, and words are separated by underscores, e.g., MAX_VALUE, PI, DEFAULT_TIMEOUT.

Here are some additional tips:

  • Use descriptive names that clearly indicate the purpose of the variable or method.
  • Avoid abbreviations or acronyms unless they are widely understood within the context of your code.
  • Be consistent with your chosen conventions throughout your project.

Cheat sheet

C# naming conventions help keep code organized and maintainable:

  • PascalCase: For class names, method names, and property names
    MyClass, CalculateTotal, FirstName
  • camelCase: For local variables and method parameters
    myVariable, customerName, calculateTotal
  • _underscorePrefix: For private fields (underscore + camelCase)
    _myPrivateField, _customerAge
  • UPPER_CASE: For constants (uppercase with underscores)
    MAX_VALUE, PI, DEFAULT_TIMEOUT

Additional tips:

  • Use descriptive names that clearly indicate purpose
  • Avoid abbreviations unless widely understood
  • Be consistent throughout your project

Try it yourself

This lesson doesn't include a code challenge.

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals