VB.NET 中的方法组? [英] Method group in VB.NET?

查看:26
本文介绍了VB.NET 中的方法组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

James Michael Hare 最近写了一篇博文 关于 Char 静态方法.他谈到使用方法组来编写不那么冗长的 LINQ:

James Michael Hare recently wrote a blog post about Char static methods. He talks about using a method group to write less-wordy LINQ:

if (myString.Any(c => char.IsLower(c))) { xyzzy(); }
if (myString.Any(char.IsLower)) { xyzzy(); } // Less wordy FTW!

VB.NET 中的等效项是:

The equivalent in VB.NET would be:

If myString.Any(Function(c) Char.IsLower(c)) Then xyzzy()
If myString.Any(Char.IsLower) Then xyzzy() 'Compiler error

遗憾的是,我不能在这里做等效的 C#...编译器告诉我 重载解析失败,因为没有可访问的 'IsLower' 接受这个数量的参数...悲伤.我认为这可能是因为我打开了 Option Strict,但可惜,这也不起作用.

Sadly, I can't do the equivalent of C# here... the compiler tells me that Overload resolution failed because no accessible 'IsLower' accepts this number of arguments... sadness. I thought it might be caused by me having Option Strict on, but alas, that didn't work either.

我假设 方法组 在 VB.NET 中不可用... VB.NET 中是否有类似的功能可用?或者为什么这不能(不会)在 VB.NET 中完成?

I'm assuming method groups aren't availablet in VB.NET... Is there a similar feature available in VB.NET? Or any particular reason why this can't (won't) be done in VB.NET?

推荐答案

等效的 VB 代码为:

The equivalent VB code would be:

If myString.Any(AddressOf Char.IsLower) Then xyzzy()

这篇关于VB.NET 中的方法组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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