How can I use a generic function that has a return type, without specifying it, in C#?

Viewed 101

I want to use it without generic argument, but I get a compile error.

How can I fix it?

public static int TestFunction(byte[] b)
{
    return 0;
}

public static void Map<T, R>(Func<T, R> b)
{

}

public static int Main(string[] args)
{
    // It's ok
    Map<byte[], int>(HttpServerHandler.TestFunction);

    // Error CS0411  The type arguments for method 'HttpServerHandler.Map<T, R>(Func<T, R>)' cannot be inferred from the usage.Try specifying the type arguments explicitly.
    Map(HttpServerHandler.TestFunction);
    return 0;
}
0 Answers
Related