Sunday, September 24, 2006

Defining a generic method in a non-generic class

For instance:


class Class2
{
public static void GenericMethod <X>(int n)
where X:new()
{
X myXinstance = new X();
}
}

The method can be called like this:
Class2.GenericMethod <System.Collections.ArrayList> (100);

No comments: