Skip to main content
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
C# identifier naming rules and conventions
- Article
- 03/29/2022
- 2 minutes to read
In this article
An identifier is the name you assign to a type [class, interface, struct, record, delegate, or enum], member, variable, or namespace.
Naming rules
Valid identifiers must follow these rules:
- Identifiers must start with a letter or underscore [
_
]. - Identifiers may contain Unicode letter characters, decimal digit characters, Unicode connecting characters, Unicode combining characters, or Unicode formatting characters. For
more information on Unicode categories, see the Unicode Category Database. You can declare identifiers that match C# keywords by using the
@
prefix on the identifier. The@
is not part of the identifier name. For example,@if
declares an identifier namedif
. These verbatim identifiers are primarily for interoperability with identifiers declared in other languages.
For a complete definition of valid identifiers, see the Identifiers topic in the C# Language Specification.
Naming conventions
In addition to the rules, there are many identifier naming
conventions used throughout the .NET APIs. By convention, C# programs use PascalCase
for type names, namespaces, and all public members. In addition, the following conventions are common:
- Interface names start with a capital
I
. - Attribute types end with the word
Attribute
. - Enum types use a singular noun for non-flags, and a plural noun for flags.
- Identifiers shouldn't contain two consecutive underscore [
_
] characters. Those names are reserved for compiler-generated identifiers.
For more information, see Naming conventions.
C# Language Specification
For more information, see the C# Language Specification. The language specification is the definitive source for C# syntax and usage.
See also
- C# Programming Guide
- C# Reference
- Classes
- Structure types
- Namespaces
- Interfaces
- Delegates
Feedback
Submit and view feedback for
- Click to view our Accessibility Policy
- Skip to content
- Java
- Technologies
- Java SE
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
9 - Naming Conventions
Naming conventions make programs more understandable by making them easier to read. They can also give information about the function of the identifier-for example, whether it's a constant, package, or class-which can be helpful in understanding the code.
Packages | The prefix of a unique package name is always written in all-lowercase ASCII letters and should be one of the top-level domain names, currently com, edu, gov, mil, net, org, or one of the English two-letter codes identifying countries as specified in ISO Standard 3166, 1981. Subsequent components of the package name vary according to an organization's own internal naming conventions. Such conventions might specify that certain directory name components be division, department, project, machine, or login names. | com.sun.eng com.apple.quicktime.v2 edu.cmu.cs.bovik.cheese |
Classes | Class names should be nouns, in mixed case with the first letter of each internal word capitalized. Try to keep your class names simple and descriptive. Use whole words-avoid acronyms and abbreviations [unless the abbreviation is much more widely used than the long form, such as URL or HTML]. | class Raster; class ImageSprite; |
Interfaces | Interface names should be capitalized like class names. | interface RasterDelegate; interface Storing; |
Methods | Methods should be verbs, in mixed case with the first letter lowercase, with the first letter of each internal word capitalized. | run[]; runFast[]; getBackground[]; |
Variables | Except for variables, all instance, class, and class constants are in mixed case with a lowercase first letter. Internal words start with capital letters. Variable names should not start with underscore _ or dollar sign $ characters, even though both are allowed. Variable names should be short yet meaningful. The choice of a variable name should be mnemonic- that is, designed to indicate to the casual observer the intent
of its use. One-character variable names should be avoided except for temporary "throwaway" variables. Common names for temporary variables are | Copy
|
Constants | The names of variables declared class constants and of ANSI constants should be all uppercase with words separated by underscores ["_"]. [ANSI constants should be avoided, for ease of debugging.] | static final int MIN_WIDTH = 4; static final int MAX_WIDTH = 999; static final int GET_THE_CPU = 1; |
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
Why Oracle
- Analyst Reports
- Best cloud-based ERP
- Cloud Economics
- Corporate Responsibility
- Diversity and Inclusion
- Security Practices
Learn
- What is cloud computing?
- What is CRM?
- What is Docker?
- What is Kubernetes?
- What is Python?
- What is SaaS?
What’s New
- News
- Oracle CloudWorld
- Oracle Supports Ukraine
- Oracle Red Bull Racing
- Oracle Sustainability
- Employee Experience Platform
- © 2022 Oracle
- Privacy/Do Not Sell My Info
- Ad Choices
- Careers
- YouTube