/* Parametric types, C# 2.0 only (also available with Java 1.5) */
using System;
public class cell
{
public A head;
public cell tail; // can't have list with different type objects
public cell(A h, cell t) { head=h; tail=t; }
}// cell
public class qlist0
{
// naturally polymorphic function
public static int length(cell L)
{
int ax = 0;
while (L!=null) {L=L.tail; ax++;}
return ax;
}
// artificially polymorphic function:
/*
public static void dec(cell L) where A : somesuperclass
{
while (L!=null)
{
L.head = L.head - 1;
L=L.tail;
}
}
*/
public static void Main()
{
cell A = new cell(2,new cell(3,new cell(5,null)));
cell B = new cell(1.5,new cell(3.4,null));
cell C = new cell("ab",new cell("cd",null));
Console.WriteLine(length(A));
Console.WriteLine(length(B));
Console.WriteLine(length(C));
} // main
} // qlist0