Method group in VB.NET?

て烟熏妆下的殇ゞ 提交于 2019-11-27 07:45:40

问题


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!

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

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.

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?


回答1:


The equivalent VB code would be:

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


来源:https://stackoverflow.com/questions/12803897/method-group-in-vb-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!