Simulate variadic templates in C#

前端 未结 6 948
轮回少年
轮回少年 2020-12-09 14:57

Is there a well-known way for simulating the variadic template feature in C#?

For instance, I\'d like to write a method that takes a lambda with an arbitrary set of p

6条回答
  •  悲&欢浪女
    2020-12-09 15:49

    There is no varadic support for generic type arguments (on either methods or types). You will have to add lots of overloads.

    varadic support is only available for arrays, via params, i.e.

    void Foo(string key, params int[] values) {...}
    

    Improtantly - how would you even refer to those various T* to write a generic method? Perhaps your best option is to take a Type[] or similar (depending on the context).

提交回复
热议问题