Lambda 教程和求解 Lambda 函数
是否可以将以下函数缩短为 lambda 表达式?
或者(我自己做这个技巧)对于初学者来说,vb.net 中的 lambda 最好、最容易理解的教程是什么?
Function getit(ByVal wert As Integer, ByVal sk As Integer, ByVal list As List(Of Array)) As String
Dim ergebnis As String
ergebnis = "Null"
For Each strg As String() In list
If wert >= Integer.Parse(strg(0)) And wert < Integer.Parse(strg(0)) + 5 And sk = Integer.Parse(strg(1)) Then
Return strg(2)
End If
Next
Return ergebnis
End Function
Is it possible to shorten the following function to a lambda expression?
Or (to do the trick by myself) what is the best and most understandable for beginners tutorial for lambda in vb.net?
Function getit(ByVal wert As Integer, ByVal sk As Integer, ByVal list As List(Of Array)) As String
Dim ergebnis As String
ergebnis = "Null"
For Each strg As String() In list
If wert >= Integer.Parse(strg(0)) And wert < Integer.Parse(strg(0)) + 5 And sk = Integer.Parse(strg(1)) Then
Return strg(2)
End If
Next
Return ergebnis
End Function
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以创建一个 lambda 表达式,它接受一个字符串数组,如果满足条件则返回 True:
我还会更改方法的签名以接受字符串数组列表而不是任何数组列表。最终的代码是:
You could create a lambda expression which takes a string array and return True if it fulfills the condition:
I would also change the signature of your method to accept a list of string array instead of a list of any array. The final code would be:
尝试一下:
Give this a try: