泛型方法、泛型接口、泛型代理、泛型類別測試,類別
using System;
using System.Collections.Generic;
public delegate void DExchange<T>(ref T t1,ref T t2);
public interface IExchange<T>
{
void Swap(ref T t1,ref T t2);
}
public class MyClass<T,V>: IExchange<T>
{
public void Swap(ref T t1,ref T t2)
{
T temp = t1;
t1 = t2;
t2 = temp;
}
public void SayHello<M>(V v1,M m1)
{
return;
}
}
public class RunMyApp
{
public static void Main()
{
string xu = "Xu Minghui";
string liu = "Liu Jie";
MyClass<string,int> my = new MyClass<string,int>();
my.Swap(ref xu,ref liu);
IExchange<string> IE = my;
IE.Swap(ref xu, ref liu);
DExchange<string> de = my.Swap;
de(ref xu, ref liu);
Console.WriteLine(xu);
Console.ReadKey();
}
}