我有一个简单的代码,当我将行更改my.Test<int>();
为时my.Test<string>();,它可以工作,但对于 int 不起作用。
class Program
{
class MyClass
{
public void Test<T>()
where T : class // Generic Constraint
{
Console.WriteLine("Hello"); // Prints Hello
}
}
static void Main()
{
MyClass my = new MyClass();
my.Test<int>();
Console.ReadKey();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4211 次 |
| 最近记录: |