C# Naming Conventions and Code Organisation

Writing code that’s clear, consistent, and well-organised is key to professional C# development. Naming conventions help everyone understand your code at a glance, while good organisation keeps projects manageable and easy to navigate.

In this session, you’ll learn the essential C# naming rules and how to structure your code effectively for readability and maintainability.


🏷️ What Are Naming Conventions?

Naming conventions are agreed-upon rules for naming variables, methods, classes, and other code elements consistently. They improve code readability and help teams avoid confusion.


🔹 Common C# Naming Rules

  • PascalCase for class names, methods, properties, and namespaces
  • camelCase for local variables and method parameters
  • ALL_CAPS for constants (rare, but sometimes used)
  • Interfaces start with a capital “I” (e.g., IRepository)
  • Avoid underscores or Hungarian notation
  • Use meaningful, descriptive names
public class CustomerAccount
{
private decimal accountBalance;

public decimal AccountBalance
{
get { return accountBalance; }
set { accountBalance = value; }
}

public void Deposit(decimal amount)
{
accountBalance += amount;
}
}

⚙️ Why Follow Naming Conventions?

Consistent naming…

  • Makes your code easier to read and understand
  • Helps teams collaborate smoothly
  • Makes maintenance and debugging simpler
  • Aligns your code with industry standards

🗂️ Organising Your Code

Good code organisation means structuring files, folders, and namespaces logically.

  • Use namespaces to group related classes, e.g., MyApp.Services
  • Organise files into folders that reflect namespaces
  • Keep classes focused; avoid large, monolithic classes
  • Use regions in files to group related methods or properties (optional)
  • Write clear comments and summaries to document your code

🔸 Example: Namespace and Folder Structure

/MyApp
/Models
Customer.cs
Order.cs
/Services
PaymentService.cs
NotificationService.cs
/Controllers
CustomerController.cs

🧠 Why Organise Code Well?

  • Helps you and others quickly find and understand code
  • Supports modular design and easier testing
  • Reduces complexity and technical debt

🧪 Practice Exercise

Create a simple project with:

  • A namespace LibraryManagement
  • Two folders: Models and Services
  • A Book class in Models using PascalCase naming
  • A LibraryService class in Services with methods named in PascalCase
  • Apply camelCase for method parameters and local variables

📚 Summary

ConceptPurpose
PascalCaseClasses, methods, properties, namespaces
camelCaseLocal variables, method parameters
Namespaces & FoldersLogical grouping of related code
ConsistencyImproves readability and maintainability

📬 Need help applying naming conventions or organising your real-world C# projects? Get in touch — I’m here to guide you step-by-step to professional coding habits.