0
0
C Sharp (C#)programming~5 mins

Naming conventions in C#

Choose your learning style9 modes available
Introduction

Naming conventions help make your code easy to read and understand by everyone.

When creating variables to store data like numbers or text.
When defining methods that perform actions or calculations.
When naming classes that represent objects or concepts.
When writing constants that never change their value.
When working in a team to keep code consistent and clear.
Syntax
C Sharp (C#)
PascalCase for classes, methods, and properties
camelCase for local variables and method parameters
ALL_CAPS with underscores for constants

PascalCase means each word starts with a capital letter, like MyClass.

camelCase means the first word starts lowercase, and next words start uppercase, like myVariable.

Examples
Class and method names use PascalCase.
C Sharp (C#)
public class CustomerAccount
{
    public int AccountNumber { get; set; }
    public void CalculateBalance() { }
}
Local variables use camelCase.
C Sharp (C#)
int itemCount = 5;
string userName = "Alice";
Constants use ALL_CAPS with underscores if needed.
C Sharp (C#)
const double PI = 3.14159;
Sample Program

This program shows naming conventions: constant in ALL_CAPS, local variable in camelCase, and class/method in PascalCase.

C Sharp (C#)
using System;

public class Program
{
    const int MAX_USERS = 100;

    public static void Main()
    {
        int currentUsers = 10;
        Console.WriteLine($"Max users allowed: {MAX_USERS}");
        Console.WriteLine($"Current users: {currentUsers}");
    }
}
OutputSuccess
Important Notes

Follow these conventions to make your code easier to read and maintain.

Consistency is more important than the exact style chosen.

Use meaningful names that describe what the item represents.

Summary

Use PascalCase for classes, methods, and properties.

Use camelCase for local variables and method parameters.

Use ALL_CAPS for constants.