Is it possible to create a method with a dynamic amount of generic parameters?

22 views Asked by At

I have method GenerateMessage which takes a dynamic amount of generic parameters is it possible to create only one method which will take a dynamic amount of parameters, or I can only write overloads?

static void Main(string[] args)
{
     Console.WriteLine(GenerateMessage("str 1", "str 2", (t, m) => t + " | " + m));
     Console.WriteLine(GenerateMessage(1, 2, (t, m) => t + " | " + m));
}

public static string GenerateMessage<T1>(T1 t1, Func<T1, string> f) => f(t1);
public static string GenerateMessage<T1, T2>(T1 t1, T2 t2, Func<T1, T2, string> f) => f(t1, t2);
public static string GenerateMessage<T1, T2, T3>(T1 t1, T2 t2, T3 t3, Func<T1, T2, T3, string> f) => f(t1, t2, t3);

0

There are 0 answers