C# Reference

Summary reference sheets for C#

Conditional Statement Facts

The following table describes three conditional blocks available with C#.

The following table shows common data type keywords.

.NET Framework Components

The .NET framework is a collection of classes and the platform that runs your applications. The .NET framework is made up of a number of components.

Term Description
Microsoft Intermediate Language (MSIL)

All .NET programs compile to Microsoft Intermediate Language (MSIL) or IL. Remember these key points about IL:

Object-oriented Programming Concepts

An object-oriented program is a collection of objects sending messages to one another. The following table lists several terms with which you should be familiar.

. . . is defined in an assembly that is not referenced. You must add a reference to assembly


There could be a number of reason you are receiving the error above in C#, but perhaps the first thing you should check is the are references within your projects.

For example if you created classOne and classTwo and classTwo inherits classOne, you need to be sure to not only qualify the use of classOne in classTwo with 'using namespace classOne', but you also have to add a reference to classOne's dll in classTwo if you built classOne's dll.

Abstract classes allow for other classes to be derived from it.  However, an instantiation of the base class type (i.e. the abstract class) cannot be done.  To declare a class abstract, place the word 'abstract' between the access modifiers and the class keyword. 

Example:

public abstract class Vehicle
{
}

Within abstract classes you can have

In C#, when you have a method in a base class that you would like to use in a derived class but with some modifications you are overriding a method.  When overriding a method in a derived class you must have the exact same signature as the method you are going to override in the base class.  In addition, it is good practice to include the virtual keyword in the signature of the base class method that is to be overridden by a derived class method.

Example method in base class:

A signature of a method consists of:

  1. The name of the method (e.g. Main(), ComputeCost(), OtherUserDefinedMethodName())
  2. Modifiers (public, public static, private, private static, etc...)
  3. Types of its formal parameters

The formal parameters are inside the method parenthesis.  Examples include:

Below is a list of properties available for the List Box control

The difference between instance methods and class methods in C#  is the use of the static keyword.  When you write your own class and a method within your class is written with the static keyword a single copy of the method is used for all objects.    You can use your static method within other methods in your class by simply typing the identifier.  However, if you call the method from another class, the class name must be used with the method name.  One example of this is a call to the Parse() method.