我是 C# 新手,我正在尝试制作一个泛型类型调度程序(类似于 C++),但看起来我无法使用泛型参数调用函数:
示例代码:
class Program
{
static void Main(string[] args)
{
DoSomething(1);
}
static void DoSomething<T>(T value)
{
//error CS1503: Argument 1: cannot convert from 'T' to 'int'
DoSomethingElse(value);
}
static void DoSomethingElse(int a)
{
Console.Write("int\n");
}
static void DoSomethingElse(float a)
{
Console.Write("float\n");
}
}
能否请您解释一下为什么我不能调用DoSomethingElse
从DoSomething
?我如何转发value
到另一个接受该特定类型的函数?
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句