VB.NET lambda 表达式示例

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4884011/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 15:16:34  来源:igfitidea点击:

Examples of VB.NET lambda expression

vb.netlinq

提问by Drake

Where can I find complex LINQ examples made using VB.NET Lambda Expression syntax?

在哪里可以找到使用 VB.NET Lambda 表达式语法制作的复杂 LINQ 示例?

During my searches I always found 101 LINQ Samplesbut they use the other notation and for me is not always clear how to transform that code into a lambda expression.

在我的搜索过程中,我总能找到101 个 LINQ 示例,但它们使用其他表示法,对我来说并不总是清楚如何将该代码转换为 lambda 表达式。

回答by sloth

You could just look at MSDN. They have at least one example for each of the IEnumerable-extensions in C# and also in VB.Net.

你可以看看MSDN。对于 C# 和 VB.Net 中的每个 IEnumerable 扩展,他们至少有一个示例。

Some random examples:

一些随机示例:

' Select
Dim squares As IEnumerable(Of Integer) = _
        Enumerable.Range(1, 10).Select(Function(x) x * x)

' Aggregate
Dim reversed As String = _
        words.Aggregate(Function(ByVal current, ByVal word) word & " " & current)

' Max
Dim max As Integer = pets.Max(Function(pet) _
                                      pet.Age + pet.Name.Length)

 ' SkipWhile
Dim query As IEnumerable(Of Integer) = _
        amounts.SkipWhile(Function(amount, index) _
                              amount > index * 1000)