http://blog.csdn.net/aladdinty/article/details/3486532
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace 泛型
- {
- class 泛型接口
- {
- public static void Main()
- {
- PersonManager man = new PersonManager();
- Person per = new Person();
- man.PrintYourName(per);
- Person p1 = new Person();
- p1.Name = "p1";
- Person p2 = new Person();
- p2.Name = "p2";
- man.SwapPerson<Person>(ref p1, ref p2);
- Console.WriteLine( "P1 is {0} , P2 is {1}" , p1.Name ,p2.Name);
- Console.ReadLine();
- }
- }
- //泛型接口
- interface IPerson<T>
- {
- void PrintYourName( T t);
- }
- class Person
- {
- public string Name = "aladdin";
- }
- class PersonManager : IPerson<Person>
- {
- #region IPerson<Person> 成员
- public void PrintYourName( Person t )
- {
- Console.WriteLine( "My Name Is {0}!" , t.Name );
- }
- #endregion
- //交换两个人,哈哈。。这世道。。
- //泛型方法T类型作用于参数和方法体内
- public void SwapPerson<T>( ref T p1 , ref T p2)
- {
- T temp = default(T) ;
- temp = p1;
- p1 = p2;
- p2 = temp;
- }
- }
- }