C# Keywords

Review keywords from the C# language. Each keyword has a link to an example and a description.


The glacier is a harsh place for living creatures. The air itself is frozen. Even the polar bear seeks refuge in a cave. A visitor to this icy world must find a way to survive.

Like a fire

brings warmth to this winter place, a keyword brings meaning to a program. We use keywords to control (to master) the program's logic.abstractasascendingasyncawaitbaseboolbreakbytecasecatchcharcheckedclassconstcontinuedecimaldefaultdelegatedescendingdodoubledynamicelseenumequalseventexplicitexternfalsefinallyfixedfloatforforeachfromgetgotogroupifimplicitinintinterfaceinternalisjoinletlocklongnameofnamespacenewnullobjectoperatororderbyoutoverrideparamspartialprivateprotectedpublicreadonlyrefreturnsbytesealedselectsetshortsizeofstackallocstaticstringstructswitchthisthrowtruetrytypeofuintulonguncheckedunsafeushortusingvaluevarvirtualvoidvolatilewhenwherewhileyield

Syntax hints.

A question mark can mean a ternary statement, or a nullable type. A period can mean a member access or a floating-point number.[A] (Attribute)// ... (Comment)/* ... */ (Comment)~C (Destructor)# (Directive){0} (Format)<T> (Generic){[0] = 1} (Indexer initializer): (Inheritance)=> (Lambda)% (Modulo)? (Nullable)?? (Null coalescing)?. (Null conditional)D (Numeric suffix)$"{x}" (String interpolation)? (Ternary)* (Unsafe)(1, "x") (ValueTuple)@ (Verbatim literal)

Reserved versus contextual.

Here is an important part of the syntax of C#. Some terms, like "for," are reserved keywords—we cannot name a variable "int for."

Reserved, continued.

Other terms, like "where," are contextual keywords. They have a special meaning in a certain place (like a query expression) but we can name a variable "where."

A final note.

For survival in the arctic world, tiny syntax details are less important. The big picture is what matters. Know first the important things like string and int.
Dot Net Perls
© 2007-2019 Sam Allen. All rights reserved. Written by Sam Allen,