C# MEMO@klopix
Nov 3 2007
 

All the components you put to your form are comprised by the form. They become private members of the form.

System.Windows.Forms.Form inherits :

MarshalByRefObject

garantees that the object of this type is to be called only by reference.

Component

Some practically not interesting stuff.

Control

comprises the following properties: methods: events:

ScrollableControl

This class is needed to provide horizontal and vertical scroll ability.

Properties (are to be places into form constructor):

ContainerControl

The most important properties and methods:

Form

Some important properties: and some methods: and some events:

Nov 2 2007
 

Crucial functions

Nov 1 2007
 

Assembly .NET

Manifest [assembly metadata: entire list of dependences to another assemblies, version of the assembly(identifier: informational version + compatibility version; compatibility version: W.X.Y.Z; W is major, X is minor, Y is build number, Z is revision number )]
Type metadata [includes info about whether a type is public or private i.e. could be used outside or hidden for outer usage]
Intermediate Language code [it's somewhat like assembler code but not native, i.e. assembler for every type of processor where the IL code to native code converter is written]

Example: single-file assembly using


using System;
using System.Collections.Generic;
using System.Text;

namespace SeasonLibrary
{
    public enum SeasonState
    {
        Winter,
        Spring,
        Summer,
        Autumn
    }
    public interface Season
    {
        void perform();
    }
    public class Winter: Season
    {
        public void perform()
        {
            Console.WriteLine( "Snowing..." );
        }
    }
    public class Spring : Season
    {
        public void perform()
        {
            Console.WriteLine("Getting warm...");
        }
    }
    public class Summer : Season
    {
        public void perform()
        {
            Console.WriteLine("Very very hot...");
        }
    }
    public class Autumn : Season
    {
        public void perform()
        {
            Console.WriteLine("Everything is yellow and red...");
        }
    }
}


// CLIENT APPLICATION, HAVING REFERENCE TO THE LIBRARY
using System;
using System.Collections.Generic;
using System.Text;

namespace SeasonApp
{
    class Program
    {
        static void Main(string[] args)
        {
            SeasonLibrary.Season[] sa = new SeasonLibrary.Season[4];
            sa[0] = new SeasonLibrary.Winter();
            sa[1] = new SeasonLibrary.Spring();
            sa[2] = new SeasonLibrary.Summer();
            sa[3] = new SeasonLibrary.Autumn();

            for (int i = 0; i < sa.Length; ++i)
                sa[i].perform();
        }
    }
}

//OUTPUT
//Snowing...
//Getting warm...
//Very very hot...
//Everything is yellow and red...

Oct 31 2007
 

ICloneable

If you wanna have a deep copy but not a shallow copy which is just one more link to the same object in the memo, you should derive your class from the IClonable interface and realize the IClonable.Clone() method. The simpliest way is just return new object of this one:

class X: IClonable
{
	public X(params)
	{
		//...
	}
	public object Clone()
	{
		return new X(params);
	}
}

The only thing you should know before you do that is that you didn't derive your class from some another class allready supporting this IClonable interface!

IComparable

Derive your class from IComparable and realize int CompareTo(object o); method. And at the same time returning value should be: As you've allready understood, the way you compare these two objects is entirely your business.

Indexer

Is a little bit modified property with the name this and square brackets [int pos] and some returning type (no matter whichever):
Indexer example

Oct 26 2007
 

Classical inheritance

is a relationship is-a. And there is another way to reuse written classes inside your classes having name has-a.

Internal & public classes/structures/enumerations/etc

You can declare your class either internal or public to close you class inside the namespace or to make it usable outside the namespace.

Constructors

If you made at least one constructor for a class then the default constructor is not generated automatically. You should write it by yourself.

Another terms

Class method's version control example

Interface

Example: implicit method definition

But if you wanna derive your class from two different interfaces with the same called methods and then use both those methods you just define explicitly both realizations for both interfaces in the end class: Example: explicit method definition

    interface PPPConnection
    {
        void Connect();
    }
    interface WIFIConnection
    {
        void Connect();
    }
    // Explicit interface definition
    class Connection : PPPConnection, WIFIConnection
    {
        void PPPConnection.Connect()
        {
            Console.WriteLine( "Making a ppp connection" );
        }
        void WIFIConnection.Connect()
        {
            Console.WriteLine( "making a WiFi connection" );
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Connection c = new Connection();
            ((PPPConnection)c).Connect();
            ((WIFIConnection)c).Connect();
        }
    }

    //OUTPUT
    Making a ppp connection
    Making a WiFi connection

Enumerable class

To make your class working in foreach() operator you should do the following:
Enumerable class example: cars