I'm new to C# and I'm trying to make a generic type dispatcher (C++ like), but it looks like I can't call a function with a generic parameter:
Sample code:
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");
}
}
Can you please explain why I can't call DoSomethingElse
from DoSomething
?
How may I forward value
to another function that accepts that specific type?