您可以使用params关键字的委托?
我想定义一个委托,它需要几个日期,数目不详的其他参数(使用params关键字),并返回对象列表;
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 objects;
Func<DateTime, DateTime, params int[], List<object>>
Visual Studio中不喜欢这让我觉得这个语法是不允许的。谁能告诉我为什么?
Visual Studio doesn't like the syntax which is making me think this isn't allowed. Can anyone tell me why?
您不能有一个泛型类型参数自定义属性(CLI不会允许它),以及C#编译器实现的 PARAMS
关键字 System.ParamArrayAttribute
上的相关方法的参数。
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.
这阻止你使用它与System.Func&LT; ...&GT;泛型委托,但你总是可以创建一个不使用自己的委托类型 PARAMS
。
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
.