您可以使用params关键字的委托? [英] Can you use the params keyword in a delegate?

查看:151
本文介绍了您可以使用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.

这篇关于您可以使用params关键字的委托?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆