假设我有这样一个类:
static class TestClass<T>
{
public static void TestMethod(T t)
{
}
}
有什么方法可以推断参数以便我可以替换它:
TestClass<int>.TestMethod(5);
用这个?
TestClass.TestMethod(5);
最佳答案
不是类是通用的。然而,只使方法静态确实有效:
static class TestClass
{
public static void TestMethod<T>(T t)
{
}
}
调用:
TestClass.TestMethod(5); // TestClass.TestMethod<int>(int t)
关于c# - 如何让编译器从用户创建的类中推断类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13557518/