Class Program
{
public class Test<t, s>
{
The type parameters of a generic class are available for class members
private T name;
Private S age;
Public Test (T-Name, S-age)
{
THIS.name = name;
This.age = age;
}
public void SetValue ()
{
Console.WriteLine (name. ToString ());
Console.WriteLine (age. ToString ());
Console.read ();
}
}
static void Main (string[] args)
{
test<string, int> t = new test<string, int> ("Xiaojun", 27);
T.setvalue ();
}
Note: (1) in the inheritance of a generic class, the type parameter of the parent class has been instantiated, in which case the subclass must not necessarily be a generic class;
(2) The type parameter of the parent class is not instantiated, but is derived from the subclass, that is, the parent and child classes are generic classes, and both have the same type parameters
The purpose and description of C # generic classes