Monday, September 12, 2011

C# Keywords Table

Table of C# keywords and Descriptions. C# was a language developed by the Microsoft Corporation in the late 1990’s. It is an object oriented language that resembles both C and Java. The C# keywords reflect it’s origins as an off shoot of the C language. The following C# keywords are the building blocks of the programming language. A C# program is constructed by creating a syntactically and procedurally correct program file that can be compiled by a C# compiler.




Code

Description
abstract The abstract modifier can be used with classes,
methods, properties, indexers, and events.
as The as operator is used to perform conversions between
compatible types.
base The base keyword is used to access members of the base
class from within a derived class
bool

The bool keyword is an alias of System.Boolean. It is used to
declare variables to store the Boolean values, true and false.
break The break statement terminates the closest enclosing
loop or switch statement in which it appears.
byte The byte keyword denotes an integral type that stores
values as indicated in the following table.
case The switch statement is a control statement that
handles multiple selections by passing control to one of the case statements
within its body.
catch The try-catch statement consists of a try block
followed by one or more catch clauses, which specify handlers for
different exceptions.
char The char keyword is used to
declare a Unicode character in the range indicated in the following table.
checked The checked keyword is used to control the
overflow-checking context for integral-type arithmetic operations and
conversions.
class Classes are declared using the keyword class.
const The const keyword is used to modify a declaration of a
field or local variable.
continue The continue statement passes control to the next
iteration of the enclosing iteration statement in which it appears.
decimal The decimal keyword denotes a 128-bit data type.
default The switch statement is a control statement that
handles multiple selections by passing control to one of the case statements
within its body.
delegate A delegate declaration defines a reference type that
can be used to encapsulate a method with a specific signature.
do The do statement executes a statement or a block of
statements repeatedly until a specified expression evaluates to false.
double The double keyword denotes a simple type that stores
64-bit floating-point values.
else The if-else 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.
event

Specifies an event.

explicit The explicit keyword is used to
declare an explicit user-defined type conversion operator
extern Use the extern modifier in a method declaration to
indicate that the method is implemented externally.
false In C#, the false keyword can be used as an overloaded
operator or as a literal
finally The finally block is useful for cleaning up any
resources allocated in the try block.
fixed Prevents relocation of a variable by the garbage collector.
float The float keyword denotes a simple type that stores
32-bit floating-point values.
for The for loop executes a statement or a block of
statements repeatedly until a specified expression evaluates to false.
foreach The foreach statement repeats a group of embedded
statements for each element in an array or an object collection.
goto The goto statement transfers the program control
directly to a labeled statement.
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.
in The foreach,in 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 according to the size and range shown in the following table.
interface An interface defines a contract. A class or struct that
implements an interface must adhere to its contract.
internal The internal keyword is an access modifier for types
and type members.
is The is operator is used to check whether the run-time
type of an object is compatible with a given type.
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.
long The long keyword denotes an integral type that stores
values according to the size and range shown in the following table.
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.
new

In C#, the new keyword can be used as an operator or as a modifier.

null The null keyword is a literal that represents a null
reference, one that does not refer to any object.
object The object type is an alias for System.Object in
the .NET Framework.
operator The operator keyword is used to declare an operator in
a class or struct declaration.
out The out method parameter keyword on a method parameter
causes a method to refer to the same variable that was passed into the method
override Use the override modifier to modify a method, a
property, an indexer, or an event.
params

The params keyword lets you specify a method parameter that takes an
argument where the number of arguments is variable.

private The private keyword is a member access modifier.
protected The protected keyword is a member access modifier.
public The public keyword is an access modifier for types and
type members.
readonly The readonly keyword is a modifier that you can use on
fields.
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.
return The return statement terminates execution of the
method in which it appears and returns control to the calling method.
sbyte

The sbyte keyword denotes an integral type that stores values according
to the size and range shown in the following table.

sealed A sealed class cannot be inherited.
short

The short keyword denotes an integral data type that stores values
according to the size and range shown in the following table.

sizeof The sizeof operator is used to obtain the size in
bytes for a value type.
stackalloc

Allocates a block of memory on the stack.


static Use the static modifier to declare a static member,
which belongs to the type itself rather than to a specific object.
string The string type represents a string of Unicode
characters.
struct A struct type is a value type that can contain
constructors, constants, fields, methods, properties, indexers, operators,
events, and nested types.
switch The switch statement is a control statement that
handles multiple selections by passing control to one of the case statements
within its body.
this The this keyword refers to the current instance of the
class. Static member functions do not have a this pointer.
throw The throw statement is used to signal the occurrence
of an anomalous situation (exception) during the program execution.
true

In C#, the true keyword can be used as an overloaded operator or as a
literal.

try The try-catch statement consists of a try block
followed by one or more catch clauses, which specify handlers for
different exceptions.
typeof The typeof operator is used to obtain the System.Type

object for a type.
uint

The uint keyword denotes an integral type that stores values according to
the size and range shown in the following table.


ulong

The ulong keyword denotes an integral type that stores values according
to the size and range shown in the following table.


unchecked The unchecked keyword is used to control the
overflow-checking context for integral-type arithmetic operations and
conversions.
unsafe

The unsafe keyword denotes an unsafe context, which is required for any
operation involving pointers.

ushort

The ushort keyword denotes an integral data type that stores values
according to the size and range shown in the following table.

using The using keyword has two major uses.
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.
volatile

The 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.


void

When used as the return type for a method, void specifies that the method
does not return a value.


while The while statement executes a statement or a block of
statements until a specified expression evaluates to false.

ASCII Table




ASCII stands for American
Standard Code for Information Interchange. The ASCII character set was
first published as a standard in 1967 and was last updated in 1986. The
ASCII character set was mostly used by small to mid-range computers
systems. The ASCII character set is the human readable representation
of binary numbers. The below ASCII table shows the 33 non-printable and
95 printable characters.







Dec

Hex

Oct

Char

0 0 000   null
1 1 001   start of heading
2 2 002   start of text
3 3 003   end of text
4 4 004   end of transmission
5 5 005   enquiry
6 6 006   acknowledge
7 7 007   bell
8 8 010   backspace
9 9 011   horizontal tab
10 A 012   new line
11 B 013   vertical tab
12 C 014   new page
13 D 015   carriage return
14 E 016   shift out
15 F 017   shift in
16 10 020   data link escape
17 11 021   device control 1
18 12 022   device control 2
19 13 023   device control 3
20 14 024   device control 4
21 15 025   negative acknowledge
22 16 026   synchronous idle
23 17 027   end of trans. block
24 18 030   cancel
25 19 031   end of medium
26 1A 032   substitute
27 1B 033   escape
28 1C 034   file separator
29 1D 035   group separator
30 1E 036   record separator
31 1F 037   unit separator
32 20 040   space
33 21 041 !  
34 22 042 "  
35 23 043 #  
36 24 044 $  
37 25 045 %  
38 26 046 &  
39 27 047 '  
40 28 050 (  
41 29 051 )  
42 2A 052 *  
43 2B 053 +  
44 2C 054 ,  
45 2D 055 -  
46 2E 056 .  
47 2F 057 /  
48 30 060 0  
49 31 061 1  
50 32 062 2  
51 33 063 3  
52 34 064 4  
53 35 065 5  
54 36 066 6  
55 37 067 7  
56 38 070 8  
57 39 071 9  
58 3A 072 :  
59 3B 073 ;  
60 3C 074 <  
61 3D 075 =  
62 3E 076 >  
63 3F 077 ?  


Dec

Hex

Oct

Char

Description
64 40 100 @  
65 41 101 A  
66 42 102 B  
67 43 103 C  
68 44 104 D  
69 45 105 E  
70 46 106 F  
71 47 107 G  
72 48 110 H  
73 49 111 I  
74 4A 112 J  
75 4B 113 K  
76 4C 114 L  
77 4D 115 M  
78 4E 116 N  
79 4F 117 O  
80 50 120 P  
81 51 121 Q  
82 52 122 R  
83 53 123 S  
84 54 124 T  
85 55 125 U  
86 56 126 V  
87 57 127 W  
88 58 130 X  
89 59 131 Y  
90 5A 132 Z  
91 5B 133 [  
92 5C 134 \  
93 5D 135 ]  
94 5E 136 ^  
95 5F 137 _  
96 60 140 `  
97 61 141 a  
98 62 142 b  
99 63 143 c  
100 64 144 d  
101 65 145 e  
102 66 146 f  
103 67 147 g  
104 68 150 h  
105 69 151 i  
106 6A 152 j  
107 6B 153 k  
108 6C 154 l  
109 6D 155 m  
110 6E 156 n  
111 6F 157 o  
112 70 160 p  
113 71 161 q  
114 72 162 r  
115 73 163 s  
116 74 164 t  
117 75 165 u  
118 76 166 v  
119 77 167 w  
120 78 170 x  
121 79 171 y  
122 7A 172 z  
123 7B 173 {  
124 7C 174 |  
125 7D 175 }  
126 7E 176 ~  
127 7F 177 DEL  

Reflection Examples [C#]

This example shows how to dynamically load assembly, how to create object instance, how to invoke method or how to get and set property value.
Create instance from assembly that is in your project References

The following examples create instances of DateTime class from the System assembly.
[C#]

// create instance of class DateTime
DateTime dateTime = (DateTime)Activator.CreateInstance(typeof(DateTime));


[C#]

// create instance of DateTime, use constructor with parameters (year, month, day)
DateTime dateTime = (DateTime)Activator.CreateInstance(typeof(DateTime),
new object[] { 2008, 7, 4 });


Create instance from dynamically loaded assembly

All the following examples try to access to sample class Calculator from Test.dll assembly. The calculator class can be defined like this.
[C#]

namespace Test
{
public class Calculator
{
public Calculator() { ... }
private double _number;
public double Number { get { ... } set { ... } }
public void Clear() { ... }
private void DoClear() { ... }
public double Add(double number) { ... }
public static double Pi { ... }
public static double GetPi() { ... }
}
}


Examples of using reflection to load the Test.dll assembly, to create instance of the Calculator class and to access its members (public/private, instance/static).
[C#]

// dynamically load assembly from file Test.dll
Assembly testAssembly = Assembly.LoadFile(@"c:\Test.dll");


[C#]

// get type of class Calculator from just loaded assembly
Type calcType = testAssembly.GetType("Test.Calculator");


[C#]

// create instance of class Calculator
object calcInstance = Activator.CreateInstance(calcType);


[C#]

// get info about property: public double Number
PropertyInfo numberPropertyInfo = calcType.GetProperty("Number");


[C#]

// get value of property: public double Number
double value = (double)numberPropertyInfo.GetValue(calcInstance, null);


[C#]

// set value of property: public double Number
numberPropertyInfo.SetValue(calcInstance, 10.0, null);


[C#]

// get info about static property: public static double Pi
PropertyInfo piPropertyInfo = calcType.GetProperty("Pi");


[C#]

// get value of static property: public static double Pi
double piValue = (double)piPropertyInfo.GetValue(null, null);


[C#]

// invoke public instance method: public void Clear()
calcType.InvokeMember("Clear",
BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.Public,
null, calcInstance, null);


[C#]

// invoke private instance method: private void DoClear()
calcType.InvokeMember("DoClear",
BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.NonPublic,
null, calcInstance, null);


[C#]

// invoke public instance method: public double Add(double number)
double value = (double)calcType.InvokeMember("Add",
BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.Public,
null, calcInstance, new object[] { 20.0 });


[C#]

// invoke public static method: public static double GetPi()
double piValue = (double)calcType.InvokeMember("GetPi",
BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.Public,
null, null, null);


[C#]

// get value of private field: private double _number
double value = (double)calcType.InvokeMember("_number",
BindingFlags.GetField | BindingFlags.Instance | BindingFlags.NonPublic,
null, calcInstance, null);