Code360 powered by Coding Ninjas X Code360 powered by Coding Ninjas X
Last Updated: Mar 27, 2024
Difficulty: Easy

Identifiers in C# - A Complete Guide with (Examples)

Leveraging ChatGPT - GenAI as a Microsoft Data Expert
Prerita Agarwal
Data Specialist @
23 Jul, 2024 @ 01:30 PM


A user-defined name of a program element is called an identifier in C#. A namespace, class, function, variable, or interface can all fall under this category.

Identifiers are symbols in the code used to identify a program element. Types, constants, macros, and parameters are also referred to by them. The meaning and usage of the element to which the identifier refers should be indicated.

Identifiers in C# - A Complete Guide with (Examples)

C# is a compiled programming language with compile-time identifiers. Each identifier will refer to the memory address and offset that the compiler assigned to its textual identification token during run time.

What is an Identifier in C#?

In C#, an identifier serves as a custom name for variables, methods, classes, interfaces, or other elements in a program. It starts with a letter or underscore, followed by letters, digits, or underscores. Identifiers can't be reserved keywords.

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job

Rules of Naming Identifiers in C#

Valid identifiers must adhere to the following guidelines:

  1. The first character in an identifier must be a letter or an underscore ( _ ).
  2. Unicode letter characters, decimal digit characters, Unicode linking characters, Unicode combining characters, and Unicode formatting characters can all be found in identifiers.
  3. Using the @ prefix on the identifier, you can declare identifiers that match C# keywords. The @ character is not included in the identification name.
  4. Identifiers are case-sensitive.
  5. They cannot be a C# keyword or reserved word unless prefixed with "@".
  6. They should be descriptive and meaningful to enhance code readability.
  7. Avoid using special characters such as punctuation marks, spaces, and mathematical symbols.
  8. Use camelCase for local variables and private fields, PascalCase for class names, public members, and method names.
  9. Avoid using abbreviations unless they are widely understood within the context of the application domain.

Naming conventions

There are many identifier name standards used throughout the.NET APIs in addition to the restrictions. PascalCase is used in C# programs for type names, namespaces, and all public members. In addition, the following are common conventions:

  1. The names of interfaces begin with a capital I.
  2. The word Attribute comes at the end of attribute types.
  3. Non-flags have a singular noun, while flags have a plural noun.
  4. Two consecutive underscores (_) characters should not be used in identifiers. Those names are reserved for identifiers created by the compiler.

Examples of Identifiers in C#

A Simple C# program to illustrate identifiers.

  • C#


using System;
class Ninja {
static public void Main()

// variables
int n1 = 1;

           int n2 = 2;
int sum = n1+n2;

Here, Identifiers are:

Variable names: n1, n2, and sum.

Method name Main.

Class name: Ninja

Frequently Asked Questions

Is C# different from C++?

C++ is an intermediate-level language that extends C with object-oriented capabilities, whereas C# is a high-level language. C++ compiles programs to Machine Codes, whereas C# compiles programs to CLR or Common Language Runtime.

What is C# used for?

C# may be used to construct a variety of programs and applications, including mobile apps, desktop apps, cloud-based services, websites, enterprise software, and games, just like other general-purpose programming languages.

Why is C# so popular?

C# has the advantage of constructing applications for both mobile and computer devices. The open-source community also extensively uses it to create software applications utilizing various frameworks like Mono and the.NET Framework.

Which is faster, C++ or C#?

C++ code is substantially faster than C# code, making it a superior choice for applications that require high speed. Your network analysis software, for example, may require C++ code, but performance is unlikely to be an issue for a conventional word processing application written in C#.

Is C# or C++ better for games?

C# and C++ can both be used to make games. C++, on the other hand, has better hardware control on the PC or server. As a result, it's usually a better choice for game creation. On the other hand, both languages are for game creation, especially since you won't be making games from scratch (usually).


In this article, we have extensively discussed the Label Control in C#. We hope that this blog has helped you enhance your knowledge regarding the Label Control and if you would like to learn more, check out our articles on Basics of C#Methods in C#, and Type Conversion in C#.

Refer to our guided paths on Coding Ninjas Studio to learn more about DSA, Competitive Programming, JavaScript, System Design, etc. 

Enroll in our courses and refer to the mock test and problems available.

Take a look at the interview experiences and interview bundle for placement preparations.

Topics covered
What is an Identifier in C#?
Rules of Naming Identifiers in C#
Naming conventions
Examples of Identifiers in C#
Frequently Asked Questions
Is C# different from C++?
What is C# used for?
Why is C# so popular?
Which is faster, C++ or C#?
Is C# or C++ better for games?