本文整理汇总了VB.NET中System.Linq.Queryable.Select方法的典型用法代码示例。如果您正苦于以下问题:VB.NET Queryable.Select方法的具体用法?VB.NET Queryable.Select怎么用?VB.NET Queryable.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。
在下文中一共展示了Queryable.Select方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: fruits
Dim fruits() As String = {"apple", "banana", "mango", "orange", _
"passionfruit", "grape"}
' Project an anonymous type that contains the
' index of the string in the source array, and
' a string that contains the same number of characters
' as the string's index in the source array.
Dim query = _
fruits.AsQueryable() _
.Select(Function(fruit, index) New With {index, .str = fruit.Substring(0, index)})
Dim output As New System.Text.StringBuilder
For Each obj In query
output.AppendLine(obj.ToString())
Next
' Display the output.
MsgBox(output.ToString())
输出:
{ index = 0, str = } { index = 1, str = b } { index = 2, str = ma } { index = 3, str = ora } { index = 4, str = pass } { index = 5, str = grape }
示例2: List
Dim range As New List(Of Integer)(New Integer() {1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
' Project the square of each int value.
Dim squares As IEnumerable(Of Integer) = _
range.AsQueryable().Select(Function(x) x * x)
Dim output As New System.Text.StringBuilder
For Each num As Integer In squares
output.AppendLine(num)
Next
' Display the output.
MsgBox(output.ToString())
输出:
1 4 9 16 25 36 49 64 81 100