110,476
社区成员
发帖
与我相关
我的任务
分享
static void Main(string[] args)
{
A<int> a = new A<int>();
Test(a);
A<string> b = new A<string>();
Test(b);
A<float> c = new A<float>();
Test(c);
Console.ReadLine();
}
public class A<T>
{
public void Write()
{
Console.WriteLine(typeof(T));
}
}
public static void Test<T>(A<T> a)
{
a.Write();
}
void TFunc<R,T>(R objA) where R : a<T>
{
objA.Execute();
}
建议把execute 放到非泛型的interface 上,由a<T>实现这个接口。这样你的TFunc就可以面对interface去做。调用时就不用写一大堆乱七八糟的参数了
public class Fan<T>
{
public void Some<T1,T2>(T1 t)
where T1 : Fan<T2>
{
}
}
类似这种?很抱歉我只会写C#的
public void newFunction<T>(T newParent)
where T : b
{
b.Execute1;
.....
b.Execute100();
}