C# Reference Flash Cards


PEPE: Portable Executable.

Refers to an assembly which contains an assemly manifest and MSIL code.

MSILMSIL: Microsft Intermediate Language.

The common language used by the common language runtime (CLR) to compile binary executables (EXEs, DLLs, etc.). Typically, when you compile a .Net assembly using a development tool it is not compiled to native, binary code. Instead, it is compiled to managed code called Microsoft Intermediate Language (MSIL). MSIL is then compiled to native code by the CLR (Common Language Runtime) just before the code is to be executed. Producing MSIL also produces metadata which is responsible for describing types such as classes, structs, properties and methods. The metadata also helps to describe the assembly's interfaces which means you do no longer need to rely on the older COM-style approach to registering DLLs.

CLRCLR: Common Language Runtime.

This is the heart of the .Net Framework.

privateClass members defined as private can only be accessed by the class in which they are defined.

protectedAny member of a class declared as protected can be accessed ONLY within the defining class and any deriving classes.

Structs cannot be protected because they can't be inherited.

The protected keyword can be applied to members of a class only - not the class or other types.

Static ConstructorA static constructor is used to initialize a class and is called automatically to initialize the class before the static members are accessed.

A static constructor is only called once throughout the application's lifetime. The static constructor method is called when any of the defining class' members are first accessed. The constructor is called once only.


Class and Struct ConstructorsA constructor is a method that is invoked upon instantiation of a type (class or struct).

Note: Structs can have constructors ONLY if the the method signature contains parameters.


Private ConstructorA constructor is a method that is invoked upon instantiation of a class.

Constructors can NOT have return types defined.

A private constructor is an instance constructor. It's commonly used in classes that contain static members only.

DestructorDestructors are methods that are invoked when an initialized class is destroyed. NOTE: however, it is nearly impossible to determine when an instance will absolutely be destroyed so be careful what functionality you place within a destructor method.

Note: Structs cannot contain destructors - only classes can.


IndexerIndexers provide collection/array type access to data via a class instance.

main MethodAny one class in a project that contains a Main method will be invoked upon initial execution of the application. Every application should have a Main() method defined otherwise your application wouldn't know where to start! ONLY one class in any given project/application can contain a Main method.

The main method can return either void or int and MUST be static.

abstractAn abstract class, method or property must be derived. You can not instantiate an object from a class marked as abstract. An abstract class is said to be a base class. Remember, an abstract class or member cannot be accessed directly from that class - it can only be accessed from a deriving class. Consequently, you cannot use the sealed keyword on an abstract class. Structs cannot be abstract because the type cannot be inherited. Anything marked as abstract cannot have code defined inside of it - the deriving class must do this itself. When deriving you must use the override keyword to implement the abstracted memebers of an abstract class.

constShort for constant, a member defined with const is made read-only after a value is assigned to it. Once a value is assigned to a constant it cannot be modified.

readonlyUse the readonly keyword on a field (aka variable) to ensure that it cannot be altered. The difference between a constant and readonly field is that a readonly field can also be changed within the constructor (see Class and Struct Constructors) method body of a class (a constant cannot).

eventThe event keyword is used to declare a delegate-type variable capable of raising events. When an event is raised through the event variable the target method is called through a predefined delegate. There are two components to an event: a delegate memeber and an event member.

overrideThis keyword is used with methods and properties to provide a new implementation of those members inherited from base objects.

Any class can have it's properties and methods overridden so long they are marked as virtual and they are non-static.