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

Naming conventions in C# - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Naming conventions in C#
Start Naming
Identify Type
Class
Apply PascalCase
Use Prefixes/Suffixes if needed
Finish Naming
Choose the kind of item (class, method, variable), then apply the right naming style: PascalCase for classes and methods, camelCase for variables.
Execution Sample
C Sharp (C#)
class MyClass {
  void CalculateSum() {
    int totalAmount = 0;
  }
}
Defines a class, a method, and a variable using proper C# naming conventions.
Execution Table
StepCode ElementNaming Rule AppliedName ExampleReason
1ClassPascalCaseMyClassClasses use PascalCase to start with uppercase letters.
2MethodPascalCaseCalculateSumMethods use PascalCase to start with uppercase letters.
3VariablecamelCasetotalAmountVariables use camelCase to start with lowercase letters.
4Prefix/SuffixNone used-No prefixes or suffixes needed here.
5End--Naming complete following C# conventions.
💡 All code elements named following C# naming conventions.
Variable Tracker
VariableStartAfter Naming
ClassNameunnamedMyClass
MethodNameunnamedCalculateSum
VariableNameunnamedtotalAmount
Key Moments - 3 Insights
Why do classes and methods use PascalCase but variables use camelCase?
Classes and methods use PascalCase to stand out as types and actions, starting with uppercase letters (see execution_table rows 1 and 2). Variables use camelCase starting with lowercase to show they are data holders (row 3).
Can variable names start with uppercase letters?
By convention, variables start with lowercase letters (camelCase) to distinguish them from classes and methods. Using uppercase can confuse readers (see execution_table row 3).
When should prefixes or suffixes be used in names?
Prefixes or suffixes are used rarely, for example, 'I' prefix for interfaces or 'Async' suffix for async methods. In this example, none were needed (row 4).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what naming style is used for the method 'CalculateSum'?
APascalCase
Bsnake_case
CcamelCase
DUPPERCASE
💡 Hint
Check execution_table row 2 under 'Naming Rule Applied' and 'Name Example'.
At which step does the variable get its name following the camelCase convention?
AStep 1
BStep 2
CStep 3
DStep 4
💡 Hint
Look at execution_table row 3 where the variable naming is described.
If we renamed the variable to 'TotalAmount' (starting uppercase), what would change in the variable_tracker?
AVariableName would change to 'TotalAmount' but still be camelCase
BVariableName would change to 'TotalAmount' and break camelCase convention
CClassName would change instead
DNo change would happen
💡 Hint
Refer to variable_tracker and key_moments about camelCase for variables.
Concept Snapshot
Naming conventions in C#:
- Classes and methods use PascalCase (Start with uppercase)
- Variables use camelCase (Start with lowercase)
- Prefixes/suffixes used for special cases (e.g., interfaces, async)
- Consistent naming improves code readability
- Follow these rules to write clear C# code
Full Transcript
In C#, naming conventions help keep code clear. Classes and methods use PascalCase, meaning their names start with uppercase letters, like MyClass or CalculateSum. Variables use camelCase, starting with lowercase letters, like totalAmount. Prefixes or suffixes are added only in special cases, such as 'I' for interfaces or 'Async' for asynchronous methods. Following these rules makes code easier to read and understand. The execution table shows each step naming the class, method, and variable correctly. The variable tracker shows how names change from unnamed to their final forms. Remember, variables should not start with uppercase letters to avoid confusion with classes or methods.