Can you use the params keyword in a delegate?

后端 未结 2 669
借酒劲吻你
借酒劲吻你 2021-01-03 18:37

I\'d like to define a delegate that takes a couple of dates, an unknown number of other parameters (using the params keyword), and that returns a list of object

2条回答
  •  天涯浪人
    2021-01-03 19:23

    You can't have custom attributes on a generic type argument (the CLI doesn't permit it), and the C# compiler implements the params keyword by emitting the System.ParamArrayAttribute on the relevant method parameter.

    This stops you from using it with the System.Func<...> generic delegates, but you can always create your own delegate type that does use params.

提交回复
热议问题