泛型类和方法
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 泛型类和方法
{
class Program
{
static void Main(string[] args)
{
Tperson<string, string> p1 = new Tperson<string, string>("lily","lifang");
p1.show();
Tcat<string, string,Guid > p2 = new Tcat<string, string, Guid >("名字", "地址", Guid.NewGuid());//Guid随机产生数据
p2.show();
p2.test<int>(1324);
}
}
public class Tcat<T, A, M> : Tperson<T, A>//泛型类的继承
{
private M dogName;
public Tcat() { }
public Tcat(T UserName, A addre, M Dog)//泛型构造函数
{
base.username = UserName;
base.Address = addre;
this.dogName = Dog;
}
public void show()
{
Console.WriteLine(base.username.ToString()+ base.Address.ToString()+ dogName);
}
public void test<H>(H age)//泛型方法
{
Console.WriteLine(age);
}
}
public class Tperson<T, A>//泛型类
{
private T userName;
private A address;
public T username
{
set { this.userName = value; }
get { return this.userName; }
}
public A Address
{
set { this.address = value; }
get { return this.address; }
}
public Tperson() { }
public Tperson(T user, A add)
{
this.userName = user;
this.address = add;
}
public void show()
{
Console.WriteLine("名字:" + userName + "-----地址" + address);
}
}
}