Windows Systems Programming: Spring 2004

[ Home | Syllabus | Course Notes | Assignments | Search]


.Net Types (CTS - Common Type System)

The C in FCL stands for “class,” but the FCL isn’t strictly a class library; it’s a library of types. Types can mean any of the following:

These are derived from a base class called "Object" as shown in this picture

Framework classes can contain the following members:

Here, in C#, is a class that implements a Rectangle data type:

class Rectangle
{
    // Fields
    protected int width = 1;
    protected int height = 1;

    // Properties
    public int Width
    {
        get { return width; }
        set
        {
            if (value > 0)
                width = value;
            else
                throw new ArgumentOutOfRangeException (
                    "Width must be 1 or higher");
        }
    }

    public int Height
    {
        get { return height; }
        set
        {
            if (value > 0)
                height = value;
            else
                throw new ArgumentOutOfRangeException (
                    "Height must be 1 or higher");
        }
    }

    public int Area
    {
        get { return width * height; }
    }

    // Methods (constructors)
    public Rectangle () {}
    public Rectangle (int cx, int cy)
    {
        Width = cx;
        Height = cy;
    }
}

Rectangle has seven class members:

 Notice that these properties’ set accessors throw an exception if an illegal value is entered, a protection that couldn’t be afforded had Rectangle’s width and height been exposed through publicly declared fields.
Area is a read-only property because it lacks a set accessor.

Many languages that target the .NET Framework feature a new operator for instantiating objects. The following statements create instances of Rectangle in C#:

Rectangle rect = new Rectangle ();     // Use first constructor
Rectangle rect = new Rectangle (3, 4); // Use second constructor

Once the object is created, it might be used like this:

rect.Width *= 2;      // Double the rectangle's width
int area = rect.Area; // Get the rectangle's new area
 

Storage management


Value Types


Reference Types

Characteristics


Why differentiate?


Interfaces

 


Enumerations/Delegates


Boxing

Assemblies: Organizing Managed Code

MetaData describes the types contained in a module:

This is the information used by IDLASM


 


Application Domains

 


Multi-file/language assembly (example)


Copyright chris wild 1999-2004.
For problems or questions regarding this web contact [Dr. Wild].
Last updated: January 19, 2004.