@@ -649,7 +649,7 @@ Namespace SequenceExamples
649
649
New Pet With {.Name = "Whiskers" , .Age = 1 }})
650
650
651
651
Dim output1 As New System.Text.StringBuilder
652
- ' Enumerate the items in the list, calling DefaultIfEmpty()
652
+ ' Enumerate the items in the list, calling DefaultIfEmpty()
653
653
' with a default value.
654
654
For Each pet As Pet In pets1.DefaultIfEmpty(defaultPet)
655
655
output1.AppendLine( "Name: " & pet.Name)
@@ -662,7 +662,7 @@ Namespace SequenceExamples
662
662
Dim pets2 As New List( Of Pet)
663
663
664
664
Dim output2 As New System.Text.StringBuilder
665
- ' Enumerate the items in the list, calling DefaultIfEmpty()
665
+ ' Enumerate the items in the list, calling DefaultIfEmpty()
666
666
' with a default value.
667
667
For Each pet As Pet In pets2.DefaultIfEmpty(defaultPet)
668
668
output2.AppendLine( "Name: " & pet.Name)
@@ -783,7 +783,7 @@ Namespace SequenceExamples
783
783
Dim namesList As New List( Of String ())( New String ()() {names1, names2, names3})
784
784
785
785
' Select arrays that have four or more elements and union
786
- ' them into one collection, using Empty() to generate the
786
+ ' them into one collection, using Empty() to generate the
787
787
' empty collection for the seed value.
788
788
Dim allNames As IEnumerable( Of String ) =
789
789
namesList.Aggregate(Enumerable.Empty( Of String )(),
@@ -970,7 +970,7 @@ Namespace SequenceExamples
970
970
New Pet With {.Name = "Whiskers" , .Age = 1 },
971
971
New Pet With {.Name = "Daisy" , .Age = 4 }})
972
972
973
- ' Group the pets using Age as the key
973
+ ' Group the pets using Age as the key
974
974
' and selecting only the pet's Name for each value.
975
975
Dim query As IEnumerable( Of IGrouping( Of Integer , String )) =
976
976
pets.GroupBy( Function (pet) pet.Age,
@@ -1011,7 +1011,7 @@ Namespace SequenceExamples
1011
1011
New Pet With {.Name = "Whiskers" , .Age = 1 },
1012
1012
New Pet With {.Name = "Daisy" , .Age = 4 }})
1013
1013
1014
- ' Group the pets using Age as the key
1014
+ ' Group the pets using Age as the key
1015
1015
' and selecting only the pet's Name for each value.
1016
1016
' <Snippet122>
1017
1017
Dim query =
@@ -1024,7 +1024,7 @@ Namespace SequenceExamples
1024
1024
For Each petGroup In query
1025
1025
' Print the key value of the IGrouping.
1026
1026
output.AppendLine(petGroup.Age)
1027
- ' Iterate over each value in the IGrouping
1027
+ ' Iterate over each value in the IGrouping
1028
1028
' and print the value.
1029
1029
For Each name As String In petGroup.ageGroup
1030
1030
output.AppendLine( String .Format( " {0}" , name))
@@ -1200,7 +1200,7 @@ Namespace SequenceExamples
1200
1200
Dim pets As New List( Of Pet)( New Pet() {barley, boots, whiskers, daisy})
1201
1201
1202
1202
' Create a collection where each element is an anonymous type
1203
- ' that contains a Person's name and a collection of names of
1203
+ ' that contains a Person's name and a collection of names of
1204
1204
' the pets that are owned by them.
1205
1205
Dim query =
1206
1206
people.GroupJoin(pets,
@@ -1292,7 +1292,7 @@ Namespace SequenceExamples
1292
1292
Dim pets As New List( Of Pet)( New Pet() {barley, boots, whiskers, daisy})
1293
1293
1294
1294
' Create a list of Person-Pet pairs, where each element is an
1295
- ' anonymous type that contains a Pet's name and the name of the
1295
+ ' anonymous type that contains a Pet's name and the name of the
1296
1296
' Person that owns the Pet.
1297
1297
Dim query =
1298
1298
people.Join(pets,
@@ -1526,7 +1526,7 @@ Namespace SequenceExamples
1526
1526
1527
1527
NotInheritable Class Max2
1528
1528
' <Snippet57>
1529
- ' This class implements IComparable
1529
+ ' This class implements IComparable
1530
1530
' and has a custom 'CompareTo' implementation.
1531
1531
Class Pet
1532
1532
Implements IComparable( Of Pet)
@@ -1560,7 +1560,7 @@ Namespace SequenceExamples
1560
1560
New Pet With {.Name = "Boots" , .Age = 4 },
1561
1561
New Pet With {.Name = "Whiskers" , .Age = 1 }}
1562
1562
1563
- ' Find the "maximum" pet according to the
1563
+ ' Find the "maximum" pet according to the
1564
1564
' custom CompareTo() implementation.
1565
1565
Dim max As Pet = pets.Max()
1566
1566
@@ -1642,7 +1642,7 @@ Namespace SequenceExamples
1642
1642
1643
1643
NotInheritable Class Min9
1644
1644
' <Snippet67>
1645
- ' This class implements IComparable
1645
+ ' This class implements IComparable
1646
1646
' and has a custom 'CompareTo' implementation.
1647
1647
Class Pet
1648
1648
Implements IComparable( Of Pet)
@@ -1706,7 +1706,7 @@ Namespace SequenceExamples
1706
1706
New Pet With {.Name = "Boots" , .Age = 4 },
1707
1707
New Pet With {.Name = "Whiskers" , .Age = 1 }}
1708
1708
1709
- ' Find the youngest pet by passing a
1709
+ ' Find the youngest pet by passing a
1710
1710
' lambda expression to the Min() method.
1711
1711
Dim min As Integer = pets.Min( Function (pet) pet.Age)
1712
1712
@@ -1744,7 +1744,7 @@ Namespace SequenceExamples
1744
1744
output.AppendLine(fruit)
1745
1745
Next
1746
1746
1747
- ' The following query shows that the standard query operators such as
1747
+ ' The following query shows that the standard query operators such as
1748
1748
' Where() can be applied to the ArrayList type after calling OfType().
1749
1749
Dim query2 As IEnumerable( Of String ) =
1750
1750
fruits.OfType( Of String )().Where( Function (fruit) _
@@ -1875,13 +1875,13 @@ Namespace SequenceExamples
1875
1875
' Four
1876
1876
' four
1877
1877
' First
1878
- ' first
1878
+ ' first
1879
1879
' </Snippet140>
1880
1880
# End Region
1881
1881
1882
1882
# Region "OrderByDescending"
1883
1883
' <Snippet71>
1884
- ' This class provides a custom implementation
1884
+ ' This class provides a custom implementation
1885
1885
' of the IComparer.Compare() method.
1886
1886
Class SpecialComparer
1887
1887
Implements IComparer( Of Decimal )
@@ -1961,7 +1961,7 @@ Namespace SequenceExamples
1961
1961
# Region "Range"
1962
1962
Sub RangeEx1()
1963
1963
' <Snippet72>
1964
- ' Generate a sequence of integers from 1 to 10
1964
+ ' Generate a sequence of integers from 1 to 10
1965
1965
' and project their squares.
1966
1966
Dim squares As IEnumerable( Of Integer ) =
1967
1967
Enumerable.Range( 1 , 10 ).Select( Function (x) x * x)
@@ -2142,18 +2142,18 @@ Namespace SequenceExamples
2142
2142
petOwners.SelectMany( Function (petOwner) petOwner.Pets)
2143
2143
2144
2144
Dim output As New System.Text.StringBuilder( "Using SelectMany():" & vbCrLf)
2145
- ' Only one foreach loop is required to iterate through
2145
+ ' Only one foreach loop is required to iterate through
2146
2146
' the results because it is a one-dimensional collection.
2147
2147
For Each pet As String In query1
2148
2148
output.AppendLine(pet)
2149
2149
Next
2150
2150
2151
- ' This code demonstrates how to use Select() instead
2151
+ ' This code demonstrates how to use Select() instead
2152
2152
' of SelectMany() to get the same result.
2153
2153
Dim query2 As IEnumerable( Of String ()) =
2154
2154
petOwners.Select( Function (petOwner) petOwner.Pets)
2155
2155
output.AppendLine(vbCrLf & "Using Select():" )
2156
- ' Notice that two foreach loops are required to iterate through
2156
+ ' Notice that two foreach loops are required to iterate through
2157
2157
' the results because the query returns a collection of arrays.
2158
2158
For Each petArray() As String In query2
2159
2159
For Each pet As String In petArray
@@ -2204,8 +2204,8 @@ Namespace SequenceExamples
2204
2204
New PetOwner With
2205
2205
{.Name = "Hines, Patrick" , .Pets = New String () { "Dusty" }}}
2206
2206
2207
- ' Project the items in the array by appending the index
2208
- ' of each PetOwner to each pet's name in that petOwner's
2207
+ ' Project the items in the array by appending the index
2208
+ ' of each PetOwner to each pet's name in that petOwner's
2209
2209
' array of pets.
2210
2210
Dim query As IEnumerable( Of String ) =
2211
2211
petOwners.SelectMany( Function (petOwner, index) _
@@ -2508,25 +2508,24 @@ Namespace SequenceExamples
2508
2508
2509
2509
' Sort the numbers in descending order and
2510
2510
' get all but the first (largest) three numbers.
2511
- Dim lowerGrades As IEnumerable( Of Integer ) =
2511
+ Dim skippedGrades As IEnumerable( Of Integer ) =
2512
2512
grades _
2513
- .OrderByDescending( Function (g) g) _
2514
2513
.Skip( 3 )
2515
2514
2516
2515
' Display the results.
2517
- Dim output As New System.Text.StringBuilder( "All grades except the top three are:" & vbCrLf)
2518
- For Each grade As Integer In lowerGrades
2516
+ Dim output As New System.Text.StringBuilder( "All grades except the first three are:" & vbCrLf)
2517
+ For Each grade As Integer In skippedGrades
2519
2518
output.AppendLine(grade)
2520
2519
Next
2521
2520
Console.WriteLine(output.ToString())
2522
2521
2523
2522
' This code produces the following output:
2524
2523
'
2525
- ' All grades except the top three are:
2526
- ' 82
2527
- ' 70
2528
- ' 59
2524
+ ' All grades except the first three are:
2529
2525
' 56
2526
+ ' 92
2527
+ ' 98
2528
+ ' 85
2530
2529
' </Snippet87>
2531
2530
End Sub
2532
2531
# End Region
@@ -2756,7 +2755,7 @@ Namespace SequenceExamples
2756
2755
{ "grape" , "passionfruit" , "banana" , "mango" ,
2757
2756
"orange" , "raspberry" , "apple" , "blueberry" }
2758
2757
2759
- ' Sort the strings first by their length and then
2758
+ ' Sort the strings first by their length and then
2760
2759
' alphabetically by passing the identity function.
2761
2760
Dim query As IEnumerable( Of String ) =
2762
2761
fruits _
@@ -2802,7 +2801,7 @@ Namespace SequenceExamples
2802
2801
Dim fruits() As String =
2803
2802
{ "apPLe" , "baNanA" , "apple" , "APple" , "orange" , "BAnana" , "ORANGE" , "apPLE" }
2804
2803
2805
- ' Sort the strings first by their length and then
2804
+ ' Sort the strings first by their length and then
2806
2805
' by using a custom "case insensitive" comparer.
2807
2806
Dim query As IEnumerable( Of String ) =
2808
2807
fruits _
@@ -2895,7 +2894,7 @@ Namespace SequenceExamples
2895
2894
New Package With
2896
2895
{.Company = "Adventure Works" , .Weight = 33.8 , .TrackingNumber = 4665518773L }})
2897
2896
2898
- ' Create a Dictionary that contains Package values,
2897
+ ' Create a Dictionary that contains Package values,
2899
2898
' using TrackingNumber as the key.
2900
2899
Dim dict As Dictionary( Of Long , Package) =
2901
2900
packages.ToDictionary( Function (p) p.TrackingNumber)
@@ -2929,7 +2928,7 @@ Namespace SequenceExamples
2929
2928
{ "apple" , "passionfruit" , "banana" , "mango" ,
2930
2929
"orange" , "blueberry" , "grape" , "strawberry" }
2931
2930
2932
- ' Project the length of each string and
2931
+ ' Project the length of each string and
2933
2932
' put the length values into a List object.
2934
2933
Dim lengths As List( Of Integer ) =
2935
2934
fruits _
@@ -2979,9 +2978,9 @@ Namespace SequenceExamples
2979
2978
New Package With
2980
2979
{.Company = "Wide World Importers" , .Weight = 33.8 , .TrackingNumber = 4665518773L }})
2981
2980
2982
- ' Create a Lookup to organize the packages.
2981
+ ' Create a Lookup to organize the packages.
2983
2982
' Use the first character of Company as the key value.
2984
- ' Select Company appended to TrackingNumber
2983
+ ' Select Company appended to TrackingNumber
2985
2984
' as the element values of the Lookup.
2986
2985
Dim lookup As ILookup( Of Char , String ) =
2987
2986
packages.ToLookup( Function (p) _
@@ -3049,15 +3048,15 @@ Namespace SequenceExamples
3049
3048
3050
3049
' This code produces the following output:
3051
3050
'
3052
- ' 5
3053
- ' 3
3054
- ' 9
3055
- ' 7
3056
- ' 8
3057
- ' 6
3058
- ' 4
3059
- ' 1
3060
- ' 0
3051
+ ' 5
3052
+ ' 3
3053
+ ' 9
3054
+ ' 7
3055
+ ' 8
3056
+ ' 6
3057
+ ' 4
3058
+ ' 1
3059
+ ' 0
3061
3060
' </Snippet109>
3062
3061
End Sub
3063
3062
# End Region
@@ -3070,7 +3069,7 @@ Namespace SequenceExamples
3070
3069
{ "apple" , "passionfruit" , "banana" , "mango" ,
3071
3070
"orange" , "blueberry" , "grape" , "strawberry" })
3072
3071
3073
- ' Restrict the results to those strings whose
3072
+ ' Restrict the results to those strings whose
3074
3073
' length is less than six.
3075
3074
Dim query As IEnumerable( Of String ) =
3076
3075
fruits.Where( Function (fruit) fruit.Length < 6 )
0 commit comments