如何将附加参数传递给谓词?
我的问题是通过传递特定日期从(日历)列表中查找确切的一个日历对象。我了解了谓词,但不确定是否向其传递参数。
colorcode 是列表(日历),日历类有一个名为 DtmDate 的属性,我想与它进行比较并返回所需的对象。
Dim a As Calendar = colourcode.Find(AddressOf New Calendar.FindByDate)
我从谷歌得到了谓词样本并达到了现在。但不知道如何将我的参数(即日期)传递给它。
My issue is to Find exact one Calendar object from a List Of(Calendar) by passing a particular date. I got to know about the predicate but not sure about passing parameter to it.
colorcode is List Of (Calendar) and calendar class has a property called DtmDate with which I want to compare and return the desired object.
Dim a As Calendar = colourcode.Find(AddressOf New Calendar.FindByDate)
I got the predicate samples from Google and reached till now. But not sure how to pass my parameter i.e. date to it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须创建自己的谓词。您可以使用 lambda 来做到这一点,并通过将局部变量“提升”到其中,您可以对其进行参数化。下面是 .NET 3.5/Visual Studio 2008 的一个有点愚蠢的示例:
请注意如何更改
lookFor
的值以搜索其他字符串。在 .NET 4/Visual Studio 2010 中,Visual Basic 具有更具表现力的 lambda 表达式:
You will have to create your own predicate. You can do that using a lambda and by "lifting" local variables into it you can parametrize it. Here is an somewhat silly example for .NET 3.5/Visual Studio 2008:
Notice how you can change the value of
lookFor
to search for other strings.In .NET 4/Visual Studio 2010 Visual Basic has more expressive lambda expressions: