Listing 1a: A stack of int

public class Stackofint
{
  private int[] items;
  private int total;
  public Stack(int stacksize)
  {
     items = new object[stacksize];
  }
  public void Push(int x)
  {
    items[total++] = x;
  }

  public int Pop()
  {
	return items[--total];
  }
}

Listing 1b: A stack of Person

public class StackofPerson
{
  private Person[] items;
  private int total;
  public Stack(int stacksize)
  {
     items = new object[stacksize];
  }
  public void Push(Person x)
  {
    items[total++] = x;
  }

  public Person Pop()
  {
	return items[--total];
  }
}

Listing 2: A stack of Person

public class Stack
{
  private object[] items;
  private int total;
  public Stack(int stacksize)
  {
     items = new object[stacksize];
  }
  public void Push(object x)
  {
    items[total++] = x;
  }

  public object Pop()
  {
	return items[--total];
  }
}

Listing 3

public class Stack<T>
{
  private T[] items;
  private int total;
  public Stack(int stacksize)
  {
     items = new object[stacksize];
  }
  public void Push(T x)
  {
    items[total++] = x;
  }

  public T Pop()
  {
	return items[--total];
  }
}

Listing 4

class List<T>
{
  T[] items;
  ...
  public void Sort()
  {
    ...
    int comp = items[k].CompareTo(items[j]);
    if (comp>0) ...
    else ...
    ...
  }
}

Listing 5: Code excerpt of the proxy type

public class ControlsCollectionToIListControl : IList<Controls> {
  private ControlsCollection source;
  public ControlsCollectionToIListControl(ControlsCollection source ){
    this.source = source;
  }
  public void Add(Control element){
    this.source.Add(element);
  }
  ...
}

Listing 6: Emulating multiple inheritance

class C : A
{
  protected B b;
  public C(...){
    this.b = new B(...);
  }
  ...
  public static implicit operator B (C c){
    return c.b;
  }
}

Listing 7: Multiple inheritance based on genericity

class A<T> : A where T : new()
{
  protected T t;
  public A(){
    this.t = new T();
  }
  public static implicit operator T (A<T> source){
    return source.t;
  }
}

Listing 8: Multiple inheritance based on genericity and inner classes

class A<T> : A
  where T : IBMethods, new()
{
  protected InnerT t;
  public A(){
    this.t = new InnerT(this);
  }
  public virtual void F(...) {}
  public static implicit operator T (A<T> at){
    return at.t;
  }

  class InnerT : T { //Forbidden inheritance. There is a trap here!
    A<T> at;
    public InnerT(A<T> at){
      this.at = at;
    }
    public override void F(...){
      at.F(...);
    }
  }
}