Home     ProductivityTools     Articles     How To     C Sharp     Science News     Jokes Index     Contact Us     Submit your website     General Blog      
c# Keywords
ASP .NET
C# Utopia
How do I add text items t
How to download a file fr
How to print all values i
How to copy text to buffe
How to bind dataset to da
How to parse xml using li
How to launch Bat file
How to launch message box
How to read text file
How to append to text fil
How to set focus on a con
 
Classification
 TypeKeywords used

To modify a class, method, property, or field

abstract    const     extern      internal    new        override    private    protected    public  readonly    sealed     static        virtual       volatile    void  

To deal with object type and type conversions

 as    explicit     implicit    is    operator     sizeof     typeof  

are aliases to built in types, are specific types, or have to do with enumerations

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

To control program flow

 break     case     continue     default     do     else     for     foreach, in     goto     if
 return     switch     while

To use in exception handling

 catch     checked     finally     throw     try     unchecked

like C++ function pointers and related subjects

 delegate     event

To affect garbage collection

 fixed

to help with critical sections of code

lock

 To declare scope

 namespace

 To control object allocation/destruction

 new     stackalloc

 To affect method parameter passing

 out     params     ref

 are literals or refer to the current instance of an object

 null    false     true     this     value

 To deal with unmanaged code

 unsafe

Miscellaneous

base     void

 
 
Summary
 KeywordUsage
abstract

The abstract modifier indicates that the thing being modified has a missing or incomplete implementation. The abstract modifier can be used with classes, methods, properties, indexers, and events. Use the abstract modifier in a class declaration to indicate that a class is intended only to be a base class of other classes. Members marked as abstract, or included in an abstract class, must be implemented by classes that derive from the abstract class.

as

The as operator is like a cast operation. However, if the conversion is not possible, as returns null instead of raising an exception.

base

The base keyword is used to access members of the base class from within a derived class: 1) Call a method on the base class that has been overridden by another method. 2) Specify which base-class constructor should be called when creating instances of the derived class. A base class access is permitted only in a constructor, an instance method, or an instance property accessor. It is an error to use the base keyword from within a static method.

bool

The bool keyword is an alias of System..::.Boolean. It is used to declare variables to store the Boolean values, true and false. If you require a Boolean variable that can also have a value of null, use bool?. The default value of a bool or bool? variable is false.

break

The break statement terminates the closest enclosing loop or switch statement in which it appears. Control is passed to the statement that follows the terminated statement, if any.

byte

The byte keyword denotes an integral type that stores values. System.byte. Range is 0 to 255

case

 Control is transferred to the case statement which matches the value of the switch. The switch statement can include any number of case instances, but no two case statements can have the same value. Execution of the statement body begins at the selected statement and proceeds until the break statement transfers control out of the case body. A jump statement such as a break is required after each case block, including the last block whether it is a case statement or a default statement. With one exception, (unlike the C++ switch statement), C# does not support an implicit fall through from one case label to another. The one exception is if a case statement has no code.

If no case expression matches the switch value, then control is transferred to the statement(s) that follow the optional default label. If there is no default label, control is transferred outside the switch.

catch

 The try-catch statement consists of a try block followed by one or more catch clauses, which specify handlers for different exceptions. When an exception is thrown, the common language runtime (CLR) looks for the catch statement that handles this exception. If the currently executing method does not contain such a catch block, the CLR looks at the method that called the current method, and so on up the call stack. If no catch block is found, then the CLR displays an unhandled exception message to the user and stops execution of the program.

The try block contains the guarded code that may cause the exception. The block is executed until an exception is thrown or it is completed successfully. For example, the following attempt to cast a null object raises the NullReferenceException. It is possible to use more than one specific catch clause in the same try-catch statement. In this case, the order of the catch clauses is important because the catch clauses are examined in order. Catch the more specific exceptions before the less specific ones. The compiler will produce an error if you order your catch blocks so that a later block will never be reached. A throw statement can be used in the catch block to re-throw the exception, which has been caught by the catch statement.

char

The char keyword is used to declare a Unicode character. It is 16 bit. Range is U+0000 to U+ffff.

checked

The checked keyword is used to explicitly enable overflow-checking for integral-type arithmetic operations and conversions.

class

Classes are declared using the keyword class. only single inheritance is allowed in C#. a class can inherit implementation from one base class only. However, a class can implement more than one interface. The access levels protected and private are only allowed on nested classes. You can also declare generic classes that have type parameters; see Generic Classes for more information. A class can contain declarations of   Constructors, Destructors, Constants, Fields, Methods, Properties, Indexers, Operators, Events, Delegates,
Classes, Interfaces, Structs.

const

The const keyword is used to modify a declaration of a field or local variable. It specifies that the value of the field or the local variable is constant, which means it cannot be modified. The type of a constant declaration specifies the type of the members introduced by the declaration. A constant expression must yield a value of the target type, or of a type that can be implicitly converted to the target type. A constant expression is an expression that can be fully evaluated at compile time. Therefore, the only possible values for constants of reference types are string and null.

The constant declaration can declare multiple constants. The static modifier is not allowed in a constant declaration.  The readonly keyword differs from the const keyword. A const field can only be initialized at the declaration of the field. A readonly field can be initialized either at the declaration or in a constructor. Therefore, readonly fields can have different values depending on the constructor used. Also, although a const field is a compile-time constant, the readonly field can be used for run-time constants.

continue

The continue statement passes control to the next iteration of the enclosing iteration statement in which it appears.

decimal

The decimal keyword indicates a 128-bit data type. Compared to floating-point types, the decimal type has more precision and a smaller range, which makes it appropriate for financial and monetary calculations. precision is 28-29 significant digits.

default

 The default keyword can be used in the switch statement to Specifies the default label or in generic code to

specify the default value of the type parameter. This will be null for reference types and zero for value types.

delegate

A delegate declaration defines a reference type that can be used to encapsulate a method with a specific signature. A delegate instance encapsulates a static or an instance method. Delegates are roughly similar to function pointers in C++; however, delegates are type-safe and secure. A delegate lets you pass a function as a parameter. The type safety of delegates requires the function you pass as a delegate to have the same signature as the delegate declaration.  Delegates are the basis for events.A delegate that contains an out parameter cannot be composed.

do

The do statement executes a statement or a block of statements repeatedly until a specified expression evaluates to false.Unlike the while statement, the body loop of the do statement is executed at least once regardless of the value of the expression.

double

The double keyword denotes a simple type that stores 64-bit floating-point values. By default, a real numeric literal on the right-hand side of the assignment operator is treated as double. However, if you want an integer number to be treated as double, use the suffix d or D.

else

The if statement selects a statement for execution based on the value of a Boolean expression.

enum

The enum keyword is used to declare an enumeration, a distinct type consisting of a set of named constants called the enumerator list. Every enumeration type has an underlying type, which can be any integral type except char. The default underlying type of the enumeration elements is int. By default, the first enumerator has the value 0, and the value of each successive enumerator is increased by 1. 

event

Specifies an event. The event keyword lets you specify a delegate that will be called upon the occurrence of some "event" in your code. The delegate can have one or more associated methods that will be called when your code indicates that the event has occurred. An event in one program can be made available to other programs that target the .NET Framework common language runtime.

explicit

The explicit keyword is used to declare an explicit user-defined type conversion operator. Unlike implicit conversion, explicit conversion operators must be invoked via a cast. If a conversion operation can cause exceptions or lose information, you should mark it explicit. This prevents the compiler from silently invoking the conversion operation with possibly unforeseen consequences.

extern

Use the extern modifier in a method declaration to indicate that the method is implemented externally. A common use of the extern modifier is with the DllImport attribute. It is an error to use the abstract and extern modifiers together to modify the same member. Using the extern modifier means that the method is implemented outside the C# code, while using the abstract modifier means that the method implementation is not provided in the class. Because an external method declaration provides no actual implementation, there is no method body; the method declaration simply ends with a semicolon and there are no curly braces following the signature

false

In C#, the false keyword can be used as an overloaded operator or as a literal.false Operator :- User-defined types can define a false operator that returns the bool value true to indicate false and returns false otherwise. This is useful for types that represent true, false, and null (neither true nor false), as used in databases. Such types can be used for the controlling expression in if, do, while, and for statements and in conditional expressions. If a type defines operator false, it must also define operator true. A type cannot directly overload the conditional logical operators, but an equivalent effect can be achieved by overloading the regular logical operators and operators true and false. false Literal :- The false keyword is a literal of type bool representing the boolean value false.

finally

The finally block is useful for cleaning up any resources allocated in the try block. Control is always passed to the finally block regardless of how the try block exits.

fixed

Prevents relocation of a variable by the garbage collector. The fixed statement is only permitted in an unsafe context. The fixed statement sets a pointer to a managed variable and "pins" that variable during the execution of statement. Without fixed, pointers to managed variables would be of little use since garbage collection could relocate the variables unpredictably.

float

The float keyword denotes a simple type that stores 32-bit floating-point values. By default, a real numeric literal on the right-hand side of the assignment operator is treated as double. Therefore, to initialize a float variable use the suffix f or F. If you don't use the suffix in the previous declaration, you will get a compilation error because you are attempting to store a double value into a float variable.

for

The for loop executes a statement or a block of statements repeatedly until a specified expression evaluates to false. Because the test of expression takes place before the execution of the loop, a for statement executes zero or more times.

foreach

The foreach statement repeats a group of embedded statements for each element in an array or an object collection. The foreach statement is used to iterate through the collection to get the desired information, but should not be used to change the contents of the collection to avoid unpredictable side effects.

goto

The goto statement transfers the program control directly to a labeled statement. In the first form, the identifier indicates a label located in the current body, the same lexical scope, or an enclosing scope of the goto statement. A common use of goto is to transfer control to a specific switch-case label or the default label in a switch statement. The goto statement is also useful to get out of deeply nested loops.

if

The if statement selects a statement for execution based on the value of a Boolean expression.

implicit

The implicit keyword is used to declare an implicit user-defined type conversion operator. By eliminating unnecessary casts, implicit conversions can improve source code readability. However, because implicit conversions can occur without the programmer's specifying them, care must be taken to prevent unpleasant surprises. In general, implicit conversion operators should never throw exceptions and never lose information so that they can be used safely without the programmer's awareness. If a conversion operator cannot meet those criteria, it should be marked explicit.

in

The foreach statement repeats a group of embedded statements for each element in an array or an object collection.

 int The int keyword denotes an integral type that stores values to the size Signed 32-bit integer and range -2,147,483,648 to 2,147,483,647. System.Int32
 interface An interface defines a contract. A class or struct that implements an interface must adhere to its contract. An interface can be a member of a namespace or a class and can contain signatures of Methods, Properties , Indexers, Events. An interface can inherit from one or more base interfaces.
 internal The internal keyword is an access modifier for types and type members. Internal members are accessible only within files in the same assembly. A common use of internal access is in component-based development because it enables a group of components to cooperate in a private manner without being exposed to the rest of the application code. For example, a framework for building graphical user interfaces could provide Control and Form classes that cooperate using members with internal access. Since these members are internal, they are not exposed to code that is using the framework.

 is

 The is operator is used to check whether the run-time type of an object is compatible with a given type. The is operator cannot be overloaded.

Note that the is operator only considers reference conversions, boxing conversions, and unboxing conversions. Other conversions, such as user-defined conversions, are not considered by the is operator.

 lock

 The lock keyword marks a statement block as a critical section by obtaining the mutual-exclusion lock for a given object, executing a statement, and then releasing the lock. lock ensures that one thread does not enter a critical section while another thread is in the critical section of code. If another thread attempts to enter a locked code, it will wait (block) until the object is released.

 long

 The long keyword denotes an integral type that stores values  to the size Signed 64-bit integer and range –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. System.Int64

 namespace

 The namespace keyword is used to declare a scope. This namespace scope lets you organize code and gives you a way to create globally-unique types. Even if you do not explicitly declare one, a default namespace is created. This unnamed namespace, sometimes called the global namespace, is present in every file. Any identifier in the global namespace is available for use in a named namespace. Namespaces implicitly have public access and this is not modifiable.

 new

 The new keyword can be used as an operator or as a modifier.  The new operator is used to create objects and invoke constructors. It is also used to invoke the default constructor for value types. Remember that it is an error to declare a default constructor for a struct, because every value type implicitly has a public default constructor. It is possible though to declare parameterized constructors on a struct type. The new operator cannot be overloaded. Value-type objects such as structs are created on the stack, while reference-type objects such as classes are created on the heap. The new operator cannot be overloaded. If the new operator fails to allocate memory, it throws the exception OutOfMemoryException. new can as well be used as modifier. Use the new modifier to explicitly hide a member inherited from a base class. To hide an inherited member, declare it in the derived class using the same name, and modify it with the new modifier. It is an error to use both new and override on the same member. Using the new modifier in a declaration that does not hide an inherited member generates a warning.

 nullThe null keyword is a literal that represents a null reference, one that does not refer to any object. null is the default value of reference-type variables.
 objectThe object type is an alias for System.Object in the .NET Framework. You can assign values of any type to variables of type object. All data types, predefined and user-defined, inherit from the System.Object class. The object data type is the type to and from which objects are boxed.
 operatorThe operator keyword is used to declare an operator in a class or struct declaration. Operators can only take value parameters, not ref or out parameters. Any operator declaration can be preceded by an optional attribute list.
 outThe out method parameter keyword on a method parameter causes a method to refer to the same variable that was passed into the method. Any changes made to the parameter in the method will be reflected in that variable when control passes back to the calling method. Declaring an out method is useful when you want a method to return multiple values. A method that uses an out parameter can still return a value. A method can have more than one out parameter. To use an out parameter, the argument must explicitly be passed to the method as an out argument. The value of an out argument will not be passed to the out parameter. A variable passed as an out argument need not be initialized. However, the out parameter must be assigned a value before the method returns. A property is not a variable and cannot be passed as an out parameter. An overload will occur if declarations of two methods differ only in their use of out. However, it is not possible to define an overload that only differs by ref and out.
 overrideUse the override modifier to modify a method, a property, an indexer, or an event. An override method provides a new implementation of a member inherited from a base class. The method overridden by an override declaration is known as the overridden base method. The overridden base method must have the same signature as the override method. You cannot override a non-virtual or static method. The overridden base method must be virtual, abstract, or override. An override declaration cannot change the accessibility of the virtual method. Both the override method and the virtual method must have the same access level modifier. Modifiers new, static, virtual and   abstract can not be used to modify an override method. An overriding property declaration must specify the exact same access modifier, type, and name as the inherited property, and the overridden property must be virtual, abstract, or override.
 paramsThe params keyword lets you specify a method parameter that takes an argument where the number of arguments is variable. No additional parameters are permitted after the params keyword in a method declaration, and only one params keyword is permitted in a method declaration.
 privateThe private keyword is a member access modifier. Private access is the least permissive access level. Private members are accessible only within the body of the class or the struct in which they are declared. Nested types in the same body can also access those private members.

It is a compile-time error to reference a private member outside the class or the struct in which it is declared.

 protectedThe protected keyword is a member access modifier. A protected member is accessible from within the class in which it is declared, and from within any class derived from the class that declared this member. A protected member of a base class is accessible in a derived class only if the access takes place through the derived class type. Struct members cannot be protected because the struct cannot be inherited. It is an error to reference a protected member from a class, which is not derived from the protected member's class.
 publicThe public keyword is an access modifier for types and type members. Public access is the most permissive access level. There are no restrictions on accessing public members.
 readonlyThe readonly keyword is a modifier that you 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. You can assign a value to a readonly field only in two contexts. 1) When the variable is initialized in the declaration 2) For an instance field, in the instance constructors of the class that contains the field declaration, or for a static field, in the static constructor of the class that contains the field declaration. These are also the only contexts in which it is valid to pass a readonly field as an out or ref parameter.
 ref

 The ref method parameter keyword on a method parameter causes a method to refer to the same variable that was passed into the method. Any changes made to the parameter in the method will be reflected in that variable when control passes back to the calling method. To use a ref parameter, the argument must explicitly be passed to the method as a ref argument. The value of a ref argument will be passed to the ref parameter. An argument passed to a ref parameter must first be initialized. Compare this to an out parameter, whose argument does not have to be explicitly initialized before being passed to an out parameter. A property is not a variable and cannot be passed as a ref parameter. An overload will occur if declarations of two methods differ only in their use of ref. However, it is not possible to define an overload that only differs by ref and out.

 returnThe return statement terminates execution of the method in which it appears and returns control to the calling method. It can also return the value of the optional expression. If the method is of the type void, the return statement can be omitted.
 sbyte The sbyte keyword denotes an integral type that stores values to the size Signed 8-bit integer and range -128 to 127. System.SByte.
 sealed

A sealed class cannot be inherited. It is an error to use a sealed class as a base class. Use the sealed modifier in a class declaration to prevent inheritance of the class. It is not permitted to use the abstract modifier with a sealed class. Structs are implicitly sealed; therefore, they cannot be inherited.

 short The short keyword denotes an integral data type that stores values to the size Signed 16-bit integer and range -32,768 to 32,767. System.Int16
 sizeofThe sizeof operator is used to obtain the size in bytes for a value type. The sizeof operator can be applied only to value types, not reference types. The sizeof operator can only be used in the unsafe mode. The sizeof operator cannot be overloaded.
 stackalloc

 Allocates a block of memory on the stack. A block of memory of sufficient size to contain  elements of specified type is allocated on the stack, not the heap. the address of the block is stored in the specified pointer. This memory is not subject to garbage collection and therefore does not have to be pinned (via fixed). The lifetime of the memory block is limited to the lifetime of the method in which it is defined. stackalloc is only valid in local variable initializers. Because Pointer types are involved, stackalloc requires unsafe context.

 static Use the static modifier to declare a static member, which belongs to the type itself rather than to a specific object. The static modifier can be used with fields, methods, properties, operators, events and constructors, but cannot be used with indexers, destructors, or types. A constant or type declaration is implicitly a static member. A static member cannot be referenced through an instance. Instead, it is referenced through the type name. While an instance of a class contains a separate copy of all instance fields of the class, there is only one copy of each static field. It is not possible to use this to reference static methods or property accessors.
 stringThe string type represents a string of Unicode characters. string is an alias for System.String in the .NET Framework. Although string is a reference type, the equality operators are defined to compare the values of string objects, not references.
 struct

 A struct type is a value type that can contain constructors, constants, fields, methods, properties, indexers, operators, events, and nested types. The struct type is suitable for representing lightweight objects such as Point, Rectangle, and Color. Although it is possible to represent a point as a class, a struct is more efficient in some scenarios. For example, if you declare an array of 1000 Point objects, you will allocate additional memory for referencing each object. In this case, the struct is less expensive. It is an error to declare a default (parameterless) constructor for a struct. A default constructor is always provided to initialize the struct members to their default values. It is an error to initialize an instance field in a struct. When you create a struct object using the new operator, it gets created and the appropriate constructor is called. Unlike classes, structs can be instantiated without using the new operator. If you do not use new, the fields will remain unassigned and the object cannot be used until all of the fields are initialized. There is no inheritance for structs as there is for classes. A struct cannot inherit from another struct or class, and it cannot be the base of a class. Structs, however, inherit from the base class Object. A struct can implement interfaces, and it does that exactly as classes do. Unless you need reference type semantics, a class that is smaller than 16 bytes may be more efficiently handled by the system as a struct.

 switchThe switch statement is a control statement that handles multiple selections by passing control to one of the case statements within its body. Control is transferred to the case statement whose constant-expression matches expression. The switch statement can include any number of case instances, but no two case constants within the same switch statement can have the same value. Execution of the statement body begins at the selected statement and proceeds until the jump-statement transfers control out of the case body. Notice that the jump-statement is required after each block, including the last block whether it is a case statement or a default statement. Unlike the C++ switch statement, C# does not support an explicit fall through from one case label to another. If you want, you can use goto a switch-case, or goto default. If expression does not match any constant-expression, control is transferred to the statement(s) that follow the optional default label. If there is no default label, control is transferred outside the switch.
 thisThe this keyword refers to the current instance of the class. Static member functions do not have a this pointer. The this keyword can be used to access members from within constructors, instance methods, and instance accessors. It is an error to refer to this in a static method, static property accessor, or variable initializer of a field declaration. Common uses of this are 1) To qualify members hidden by similar names. 2) To pass an object as a parameter to other methods. 3) To declare indexers.
 throwThe throw statement is used to signal the occurrence of an anomalous situation (exception) during the program execution. The thrown exception is an object whose class is derived from System.Exception. Usually the throw statement is used with try-catch or try-finally statements. When an exception is thrown, the program looks for the catch statement that handles this exception. You can also rethrow a caught exception using the throw statement.
 trueThe true keyword can be used as an overloaded operator or as a literal.
 tryThe try-catch statement consists of a try block followed by one or more catch clauses, which specify handlers for different exceptions. The try-block contains the guarded code block that may cause the exception. The block is executed until an exception is thrown or it is completed successfully. It is possible to use more than one specific catch clause in the same try-catch statement. In this case, the order of the catch clauses is important because the catch clauses are examined in order. Catch the more specific exceptions before the less specific ones.
 typeofThe typeof operator is used to obtain the System.Type object for a type. The typeof operator cannot be overloaded. To obtain the run-time type of an expression, you can use the .NET Framework method GetType
 uintThe uint keyword denotes an integral type that stores values to the size Unsigned 32-bit integer and range 0 to 4,294,967,295. System.UInt32
 ulongThe ulong keyword denotes an integral type that stores values to the size Unsigned 64-bit integer and range 0 to 18,446,744,073,709,551,615. System.UInt64.
 unchecked

The unchecked keyword is used to control the overflow-checking context for integral-type arithmetic operations and conversions. It can be used as an operator or a statement. In an unchecked context, if an expression produces a value that is outside the range of the destination type, the result is truncated. If neither checked nor unchecked is used, a constant expression uses the default overflow checking at compile time, which is checked. Otherwise, if the expression is non-constant, the run-time overflow checking depends on other factors such as compiler options and environment configuration.

 unsafeThe unsafe keyword denotes an unsafe context, which is required for any operation involving pointers. You can use the unsafe modifier in the declaration of a type or a member. The entire textual extent of the type or member is therefore considered an unsafe context. To compile unsafe code, you must specify the /unsafe compiler option. Unsafe code is not verifiable by the common language runtime.
 ushort The ushort keyword denotes an integral data type that stores values to the size  Unsigned 16-bit integer and range 0 to 65,535. System.UInt16.
 using The using keyword has two major uses. 1) using Directive   Creates an alias for a namespace or imports types defined in other namespaces. 2)
using Statement   Defines a scope at the end of which an object will be disposed.
 virtual

 The virtual keyword is used to modify a method or property declaration, in which case the method or the property is called a virtual member. The implementation of a virtual member can be changed by an overriding member in a derived class. When a virtual method is invoked, the run-time type of the object is checked for an overriding member. The overriding member in the most derived class is called, which might be the original member, if no derived class has overridden the member. By default, methods are non-virtual. You cannot override a non-virtual method. You cannot use the virtual modifier with the static, abstract and override modifiers. Virtual properties behave like abstract methods, except for the differences in declaration and invocation syntax. It is an error to use the virtual modifier on a static property. A virtual inherited property can be overridden in a derived class by including a property declaration that uses the override modifier.

 volatileThe volatile keyword indicates that a field can be modified in the program by something such as the operating system, the hardware, or a concurrently executing thread. The system always reads the current value of a volatile object at the point it is requested, even if the previous instruction asked for a value from the same object. Also, the value of the object is written immediately on assignment. The volatile modifier is usually used for a field that is accessed by multiple threads without using the lock statement to serialize access. Using the volatile modifier ensures that one thread retrieves the most up-to-date value written by another thread. The type of a field marked as volatile is restricted to the following types: 1) Any reference type. 2) Any pointer type (in an unsafe context). 3) The types sbyte, byte, short, ushort, int, uint, char, float, bool. 4) An enum type with an enum base type of byte, sbyte, short, ushort, int, or uint.
 void

When used as the return type for a method, void specifies that the method does not return a value. void is not allowed in a method's parameter list. void is also used in an unsafe context to declare a pointer to an unknown type. 

 whileThe while statement executes a statement or a block of statements until a specified expression evaluates to false. Because the test of expression takes place before each execution of the loop, a while loop executes zero or more times. A while loop can be terminated when a break, goto, return, or throw statement transfers control outside the loop. To pass control to the next iteration without exiting the loop, use the continue statement.