Using System;
Using System.Collections.Generic;
Using System.Text;
Namespace Genericity
{
Class Program
{
Generic Class 1:
public class Genericityhello<t>
{
public void SayHello (T-t)
{
Console.WriteLine (T.tostring ());
}
}
Generic class 2:
public class Genericityhello1<t>
{
Private T TT;
Public T TT
{
Get
{
return TT;
}
Set
{
tt = value;
}
}
public void SayHello ()
{
Console.WriteLine (TT. ToString ());
}
}
public class 中文版
{
public override string ToString ()
{
return "hello!";
}
}
public class Chinese
{
public override string ToString ()
{
Return "Hello!"
}
}
Generic method:
public class CLASS3
{
Public Class3 ()
{
}
public void swap<t> (ref t A, ref T B)
{
T C;
c = A;
A = b;
b = C;
}
}
static void Main (string[] args)
{
genericityhello<english> gh1 = new genericityhello<english> ();
中文版 en = new 中文版 ();
Gh1. SayHello (en);
genericityhello1<chinese> GH2 = new genericityhello1<chinese> ();
Chinese cn = new Chinese ();
Gh2.tt = CN;
Gh2. SayHello ();
To test the generic method:
Console.WriteLine ("Exchange 2 objects:");
string S1 = "Sssssssss-1";
String s2 = "Sssssssss-2";
CLASS3 CLS3 = new CLASS3 ();
Cls3. Swap (ref s1, ref S2);
Console.WriteLine ("S1={0}, S2={1}", S1, S2);
Console.ReadLine ();
}
}
}
Computer Learning Network http://www.why100000.com
Zhang Qing 2007.5.30