Tutorialsteacher

Follow Us

Articles
  • C#
  • C# OOP
  • ASP.NET Core
  • ASP.NET MVC
  • LINQ
  • Inversion of Control (IoC)
  • Web API
  • JavaScript
  • TypeScript
  • jQuery
  • Angular 11
  • Node.js
  • D3.js
  • Sass
  • Python
  • Go lang
  • HTTPS (SSL)
  • Regex
  • SQL
  • SQL Server
  • PostgreSQL
  • MongoDB
  • C# - Get Started
  • C# - Version History
  • C# - First Program
  • C# - Keywords
  • C# - Class and Objects
  • C# - Namespace
  • C# - Variables
  • C# - Implicitly-Typed Variables
  • C# - Data Types
  • Numbers
  • Strings
  • DateTime
  • Structure
  • Enum
  • StringBuilder
  • Anonymous Types
  • Dynamic Types
  • Nullable Types
  • C# - Value & Reference Types
  • C# - Interface
  • C# - Operators
  • C# - if else Statements
  • C# - Ternary Operator ?:
  • C# - Switch
  • C# - For Loop
  • C# - While Loop
  • C# - Do-while Loop
  • C# - Partial Class
  • C# - Static
  • C# - Array
  • Multidimensional Array
  • Jagged Array
  • C# - Indexer
  • C# - Generics
  • Generic Constraints
  • C# - Collections
  • ArrayList
  • List
  • SortedList
  • Dictionary
  • Hashtable
  • Stack
  • Queue
  • C# - Tuple
  • C# - ValueTuple
  • C# - Built-in Exceptions
  • Exception Handling
  • throw
  • Custom Exception
  • C# - Delegates
  • Func Delegate
  • Action Delegate
  • Predicate Delegate
  • Anonymous Methods
  • C# - Events
  • C# - Covariance
  • C# - Extension Method
  • C# - Stream I/O
  • C# - File
  • C# - FileInfo
  • C# - Object Initializer
  • OOP - Overview
  • Object-Oriented Programming
  • Abstraction
  • Encapsulation
  • Association & Composition
  • Inheritance
  • Polymorphism
  • Method Overriding
  • Method Hiding
  • C# - Solid Principles
  • Single Responsibility Principle
  • Open/Closed Principle
  • Liskov Substitution Principle
  • Interface Segregation Principle
  • Dependency Inversion Principle
  • Design Patterns
  • Singleton
  • Abstract Factory
  • Factory Method
Entity Framework Extensions - Boost EF Core 9
  Bulk Insert
  Bulk Delete
  Bulk Update
  Bulk Merge

C# Keywords

C# contains reserved words that have special meaning for the compiler. These reserved words are called "keywords". Keywords cannot be used as an identifier (name of a variable, class, interface, etc.).

Keywords in C# are distributed under the following categories:

Modifier Keywords

Modifier keywords are specific keywords that indicate who can modify types and type members. Modifiers allow or prevent certain parts of programs from being modified by other parts.

Modifier keywords
abstract
async
const
event
extern
new
override
partial
readonly
sealed
static
unsafe
virtual
volatile

Access Modifier Keywords:

Access modifiers are applied to the declaration of the class, method, properties, fields, and other members. They define the accessibility of the class and its members.

Access ModifiersUsage
publicThe Public modifier allows any part of the program in the same assembly or another assembly to access the type and its members.
privateThe Private modifier restricts other parts of the program from accessing the type and its members. Only code in the same class or struct can access it.
internalThe Internal modifier allows other program code in the same assembly to access the type or its members. This is default access modifiers if no modifier is specified.
protectedThe Protected modifier allows codes in the same class or a class that derives from that class to access the type or its members.

Statement Keywords

Statement keywords are related to program flow.

Statement Keywords
if
else
switch
case
do
for
foreach
in
while
break
continue
default
goto
return
yield
throw
try
catch
finally
checked
unchecked
fixed
lock

Method Parameter Keywords

These keywords are applied to the parameters of a method.

Method Parameter Keywords
params
ref
out

Namespace Keywords

These keywords are applied with namespace and related operators.

Namespace Keywords
using
. operator
:: operator
extern alias

Operator Keywords

Operator keywords perform miscellaneous actions.

Operator Keywords
as
await
is
new
sizeof
typeof
stackalloc
checked
unchecked

Access Keywords

Access keywords are used to access the containing class or the base class of an object or class.

Access keywords
base
this

Literal Keywords

Literal keywords apply to the current instance or value of an object.

Literal Keywords
null
false
true
value
void

Type Keywords

Type keywords are used for data types.

Type keywords
bool
byte
char
class
decimal
double
enum
float
int
long
sbyte
short
string
struct
uint
ulong
ushort

Contextual Keywords

Contextual keywords are considered as keywords, only if used in specific contexts. They are not reserved and so can be used as names or identifiers.

Contextual Keywords
add
var
dynamic
global
set
value

Contextual keywords are not converted into blue color (default color for keywords in visual studio) when used as an identifier in Visual Studio. For example, var in the below figure is not in blue, whereas the color of this is the blue color. So var is a contextual keyword.

C# Keywords

Query Keywords

Query keywords are contextual keywords used in LINQ queries.

Query Keywords
from
where
select
group
into
orderby
join
let
in
on
equals
by
ascending
descending

As mentioned above, a keyword cannot be used as an identifier (name of the variable, class, interface, etc.). However, they can be used with the prefix '@'. For example, the class is a reserved keyword, so it cannot be used as an identifier, but @class can be used as shown below.

Example: Use Keyword as Identifier
public class @class
{
    public static int MyProperty { get; set; }
}

@class.MyProperty = 100;
Try it

Visit MSDN for more information on keywords.

TUTORIALSTEACHER.COM

TutorialsTeacher.com is your authoritative source for comprehensive technologies tutorials, tailored to guide you through mastering various web and other technologies through a step-by-step approach.

Our content helps you to learn technologies easily and quickly for learners of all levels. By accessing this platform, you acknowledge that you have reviewed and consented to abide by our Terms of Use and Privacy Policy, designed to safeguard your experience and privacy rights.

[email protected]

ABOUT USTERMS OF USEPRIVACY POLICY
copywrite-symbol

2024 TutorialsTeacher.com. (v 1.2) All Rights Reserved.