Simulate variadic templates in C#

C# generics are not the same as C++ templates. C++ templates are expanded compiletime and can be used recursively with variadic template arguments. The C++ template expansion is actually Turing Complete, so there is no theoretically limit to what can be done in templates.

C# generics are compiled directly, with an empty “placeholder” for the type that will be used at runtime.

To accept a lambda taking any number of arguments you would either have to generate a lot of overloads (through a code generator) or accept a LambdaExpression.

Leave a Comment