Topic : Keywords in C# Programming | C# Identifiers:

Keywords in C#:

Keywords are predefined reserved Identifiers that have special meanings. They Can't be used as identifiers in our Program unless they include @ as a prefix. For Example: @if is a valid Identifier but only if is not valid, because it is an Keyword.

C# Reserve a Number of Words for Special use, also know as reserved words. Down, there is an table of Keywords, we can't use any of these keywords in a program as a variable or Identifiers. If we accidentally attempt to use any keywords in a Program as a variable, the compiler will generate an error.



If you want to use any of the Reserved word / keyword as an Variable, or you're not sure , whether its keyword or not. you can use "at" symbol @ with your keyword to make it variable.

For Example: case is the Keyword, and we can't use it, but we can use it like this way: @case



KeywordsDescription
AbstractThis keyword indicates that the thing being modified has a missing or incomplete implementation. We can use Abstract Modifier with Classes, Methods, Properties, indexers and Events.
asthis is an operator to perform certain types of conversion between compatible reference types or Null able types.
baseWe use this keyword to access members of the Base class from within a derived class. ( read more... )
boolWe use This keyword to declare variables to store the Boolean Values. (i.e. true or false). ( read more... )
breakWe use this keyword to terminates the loop or switch statement. ( read more... )
byteThis keyword denotes an integral type that store values from Range 0 - 255. ( read more... )
caseWe use this keyword in "switch" Statement to control the execution of statements from a list. ( read more... )
catchWe use this keyword to Handle the Exception in C#. ( read more... )
charWe used this keyword to declare variables to store the Unicode character. ( read more... )
checkedWe use this keyword to Explicitly enable overflow checking for integral-type arithmetic operations and Conversions.
classWe use this keyword to declare a Class. Class is the blue print for any functional entity which defines its properties and its function. ( read more... )
constWe use this keyword to declare a constant. constants can be number, Boolean values, string or any other.
continueWe use this keyword to pass the statement control to the next iteration of the enclosing loops statement in which it appears. ( read more... )
decimalWe use this keyword to declare a variable to store decimal values upto 28-29 significant digits. ( read more... )
defaultWe use this keyword in Switch statement or in Generic code to set an default value. ( read more... )
delegateIt is the reference type variable to hold the reference to a method. This keyword are similar to pointers to functions, in C or C++. ( read more... )
doWe use this keyword to execute a statement or a block of statements repeatedly until a specified expression evaluates to false. ( read more... )
doubleWe use this keyword to declare an variable to store an -bit floating-point values. ( read more... )
elseWe use this keyword to make decision that which statement need to run based on the value of a Boolean expression. ( read more... )
enumWe use this keyword to declare an enumeration, a Distinct type that consist of a set of named constants called the enumerator list. ( read more... )
eventWe used this keyword to declare an Event in a Publisher class. ( read more... )
explicitWe use this keyword to declares a user-defined type conversion operator that must be invoked with a cast. ( read more... )
externWe used this keyword to declare a method that is implemented externally.
false We used this keyword to returns the bool value true to indicate that an operand is False and return false otherwise
finally We use this keyword in Exception handling to finalize the process. ( read more... )
fixedWe use this statement to prevents the Garbage collector from relocating a movable variable.
floatWe used this keyword to declare an Variable that can store 32-bit floating point values. ( read more... )
forWe use this keyword to run a statement or a block of statements repeatedly until a specified expression evaluates to false. ( read more... )
foreachWe use this keyword to iterate through the collection to get the information that we want. This statement repeats a group of embedded statements for each element in an array or an object collection.
gotoWe use this keyword to transfers the Program control directly to a labeled statement.
ifWe use this statement to make decision based on the value of a Boolean expression. ( read more... )
implicitWe use this keyword to declare an implicit user-defined type conversion operator. ( read more... )
inWe use this keyword to identifies the collection to enumerate in a foreach loop.
in (Generic Modifier) We use this keyword to specifies that the parameter is contravariant. we can use this keyword in generic interfaces and delegates.
intWe used this keyword to decalre an variable to store an integral type value. ( read more... )
interfaceWe use this keyword to declare an Interface. interface provide a construct for a programmer to create types that can have methods, properties, delegates, events, and indexers declared, but not implemented. ( read more... )
internalWe use this keyword as an Access Modifier for types and type members. Internal types or members are accessible only within files in the same assembly.
isWe use this keyword to checks, if an object is compatible with a given type.
lockWe use this keyword to marks a statement block as a critical section by obtaining the mutual-exclusion lock for a given object.
longWe use this keyword to declare an variable to store an 64-bit integers. ( read more... )
namespaceWe use this keyword to declare a scope that can organize the code element and create Globally unique types. ( read more... ) We
newWe can use this keyword as an Operator (Used to create objects and invoke constructors.) , Modifier ( Used to hide an inherited member from a base class member) and a constraint (used to restrict types that might be used as arguments for a type parameter in a Generic declaration).
nullWe use this keyword to represents a Null reference, one that does not refer to any object.
objectWe use this keyword in field, method, property, and variable declarations and in cast and typeof operations.
operatorWe use this keyword to overload the built-in Operator or to provide a user-defined conversion in class or struct declaration.
outWe use this keyword to explicitly specifies that a variable should be passed by reference to a method, and set in that method.
out(Generic Modifier) We use this keyword to specifies that the type parameter is covariant. We can use this keyword in Generic interfaces and delegates.
overrideWe use this keyword to extend or modify the abstract or virtual implementation of an inherited method, property, indexer, or event.
paramsWe use this keyword to specify a method parameter that takes a variable number of arguments.
privateWe use this keyword to make the method, or property private to its enclosing class. The Private members or properties are accessible only within the body of the class or struct in which they are declared. ( read more... )
protectedWe use this keyword to protect the method or properties from the external world. The protected members is accessible within its class and by derived class instances. ( read more... )
publicWe use this keyword to make the methods or properties public to its enclosing class. the public methods are accessible from outside the class. ( read more... )
readonlyWe use this keyword as an modifier that we can use on fields. When a field declaration includes a readonly modifier, assignments to the fields introduced by the declaration can only occur as part of the declaration or in a constructor in the same class.
refWe use this keyword to pass an arguments by reference, not by value. ( read more... )
returnWe use this statement to terminates execution of the method in which it appears and returns control to the calling method.
sbyteWe use this keyword to declare an variable to store 8-bit integers value. ( read more... )
sealedWe use this keyword in class to prevents other classes from inheriting from it. ( read more... )
shortWe use this keyword to declare a variable to store an 16-bit integers. ( read more... )
sizeofWe use this operator to know the exact size of Built-in types in bytes. ( read more... )
stackallocWe use this keyword in an unsafe code context to allocate a block of memory on the stack.
staticWe use this keyword to declare a static member, which belongs to the type itself rather than to a specific object.
stringWe use this keyword to represents a zero or more Unicode characters. ( read more... )
structWe use this keyword to encapsulate small groups of related variables, such as the coordinates of a rectangle. ( read more... )
switchWe use this keyword to control the execution of statements from a list. ( read more... )
thisWe use this keyword to refers to the current instance of the class. and we also used it as a modifier of the first parameter of an extension method. ( read more... )
throwWe use this keyword to handle the exceptions during the program execution. ( read more... )
trueWe use this keyword to returns the bool value true, to indicate that an operand is true, and return false otherwise.
try We use this keyword to handle exception during the program execution. ( read more... )
typeofWe use this keyword to returns an instance of the type class when passed a name of a class. It is similar to the sizeof() Keyword in that it returns a value instead of starting a section of code.
uintWe use this keyword to declare a variable to store an unsigned 32-bit integer. ( read more... )
ulongWe use this keyword to declare an variable to store an unsigned 64-bit integers. ( read more... )
ucheckedWe use this keyword to suppress overflow-checking for integral-type arithmetic operations and conversions.
unsafeWe use this keyword to modify a procedure or define a block of code which uses unsafe code. Code is unsafe if it uses the "Address of" (&) or "Pointer Operator" (*)
ushortWe use this keyword to declare an variable to store an unsigned 16-bit integer. ( read more... )
usingWe use this keyword as a Directive ( When it is used to create an alias for a namespace or to import types define in other namespace.)
And As a Statement (When it defined a scope at the end of which an object will be disposed)
virtualWe use this keyword to modify a Method, property, indexer, or event declaration and allow for it to be overridden in a derived class.
void We use this keyword as an return type for a method. Void specifies that the method doesn't return a value.
volatileWe use this keyword to indicates that a filed might be modified by Multiple thread that are executing at the same time.
whileWe use this keyword to to executes a statement or block of statements until a specified expression evaluates to false. ( read more... )


Contextual Keywords:

A contextual keyword is used to Provide a specific Meaning in the code, but it is not a reserved word in C#. some contextual keyword, such as Partial and where have special meanings in two or more contexts.



KeywordDescription.
addWe use this contextual keyword to define a custom event accessor that is invoked when client code subscribes to our event.
AliasWe use this keyword to indicate an external alias. When we need to use several versions of the same assembly or assemblies with the same full Qualified typenames, we need to use the alias keywords to give different alias names for each version.
ascendingWe use this keyword in orderby clause in Query expressions to specify that the sort order is from smallest to largest.
asyncWe use this keyword to specify that a method is asynchronous. We we use this keyword on a method or expression, it;s referred to as an async method.
awaitWe use this keyword to a task in an asynchronous method to suspend the execution of the Method until the awaited task completes.
descendingWe use this keyword in the orderby clause in Query expressions to specify that the sort order is from largest to smallest.
dynamicWe use this keyword to enables the Operations in which it Occurs to bypass compile-time type checking, instead these operations are resolved at run time.
fromWe use this keyword to specifies the data source on which the Query will be run. and a local range variable that represents each element in the source sequence.
getWe use this keyword to defines an Accessor method in a property or indexer that retrieves the value of the Property or the indexer element.
globalWe use this keyword to resolve ambiguity between identifiers. if we have a conflict between a class name and a namespace.
groupWe use this keyword to returns a sequence of objects that contain zero or more items that match the key value for the group.
intoWe use this keyword to create a temporary identifier to store the results of a Group, join, or select clause into a new Identifier.
joinThis keyword is useful for associating elements from different source sequences that have no direct relationship in the object model.
letWe use this keyword to store the result of a sub-expression in order to use it in subsequent clauses.
orderbyWe use this keyword to returned sequence or groups to be sorted in either ascending or descending order.
partial(type)We use this keyword to define class, struct, or interface to be split into multiple files.
partial(method)We use this keywords to provide methods hooks in class.
removeWe use this keyword to define a custom event accessor that is invoked when client code unsubscribes from our event.
selectWe use this keyword in Query expression to specifies the type of values that will be produced when the Query is executed.
setWe use this keyword to define an accessor method in a property or indexer that assigns the value of the property or the indexer element.
valueWe use this keyword in the set accessor in ordinary property declarations.
varIn the Beginning in Visual C# 3.0, Variables that are declared at method scope can have an implicit type var.
where(Generic type constraint) We use this keyword in a generic type definitions to specify constraints on the types that can be used as arguments for a type parameter defined in a Generic declaration.
where(Query clause) We use this keyword in a Query expression to specify which elements from the data source will be returned in the Query expression.
yieldWe use this keyword in statement to indicate that the method, operator, or get accessor in which it appears is an iterator.


C# Identifiers:

Identifier is a name to use identify a variable, function, class, module, or any other user-defined item. an identifiers start with a letter A to Z or a to z, an underscore (_) followed by zero or more letters, and at (@) symbol.

C# is case-sensitive programming language. Thus, "InfoBrother" and "infobrother" are two different identifiers in C#.



Identifiers can have Nearly any name, bu a few restrictions apply. here are some rules to follow when creating identifiers.



  • » An identifiers must start with a letter or an underscore.
    » After the first character, it may contain numbers, letters, connectors, etc.
    » We can't use keyword as an identifiers.
    » if we are using keyword as an identifiers , it must be start with "@" at symbol.



//Following names are valid identifiers in C#:
                            
 char infoBrother;    //start with lower case letter
 char InfoBrother;    //start with upper case letter.
 char _InfoBrother;   //start with underscore:
 int @int;            //use keyword with "@" at symbol.
 double \u098info;    //a Unicode character.
                            
//Following names are not valid as an identifiers in C#:
char 5infobrother;    //Error: start with number;
char public;          //Error: public is an keyword:
double \u0027format   //Error: Unicode its an Unicode formatting character.
















I Tried my Best to Provide you complete Information regarding this topic in very easy and conceptual way. but still if you have any Problem to understand this topic, or do you have any Questions, Feel Free to Ask Question. i'll do my best to Provide you what you need.

Sardar Omar.
InfoBrother





WRITE FOR INFOBROTHER

Advertising






Advertisement