using System;
using System.Collections.Generic;
using System.Text;
namespace Generic
{
class Program
{
//声明一个泛型方法
public T getValue<T>(T t)
{
return t;
}
//调用泛型方法。注意:在调用泛型方法时,对泛型方法的类型参数实例化
public int useMethod()
{
return this.getValue<int>(10);
}
//重载getValue方法
public int getValue(int i)
{
return i;
}
//下面演示覆盖。要注意的是,泛型方法被覆盖时,约束被默认继承,不需要新指定约束关系
abstract class Parent
{
public abstract K Test<K,V>(K k,V v) where K:V;//K继承自V
}
class Child : Parent
{
public override T Test<T, S>(T t, S s)
{
return t;
}
}
static void Main(string[] args)
{
}
}
}