C# Identifiers

C# Identifiers

Identifiers in C# are the names given to program elements such as variables, methods, classes, interfaces, and namespaces. They are used to identify these elements in your code.


 What is an Identifier?

An identifier is a user-defined name.

Examples:



 Rules for C# Identifiers

✔ Must start with a letter (A–Z or a–z) or underscore (_)
✔ Can contain letters, digits, and underscores
Cannot start with a digit
Cannot be a C# keyword (unless escaped)
Case-sensitive


 Valid Identifiers



 Invalid Identifiers



 Case Sensitivity Example


 


 Using Keywords as Identifiers

You can use keywords by prefixing them with @ (not recommended).



 Naming Conventions (Best Practice)

Element Convention Example
Variables camelCase totalMarks
Methods PascalCase CalculateTotal()
Classes PascalCase StudentInfo
Constants UPPER_CASE MAX_LIMIT

 Identifiers in Different Contexts


 


 Summary

✔ Identifiers name program elements
✔ Must follow naming rules
✔ Case-sensitive
✔ Use meaningful names
✔ Follow C# naming conventions

You may also like...