forked from dotnet/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClass1.vb
343 lines (312 loc) · 12.5 KB
/
Class1.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
' *****************************************************
Option Infer On
Imports System.Collections.Generic
Module Module1
Sub Main()
Dim customers = GetCustomers()
'<Snippet1>
Dim query = From cust In customers
' ...
'</Snippet1>
'<Snippet2>
Dim londonCusts = From cust In customers
Where cust.City = "London"
' ...
'</Snippet2>
' Testing the Where lines
Dim londonC1 = From cust In customers
Where cust.City = "London" And cust.Name = "Devon"
Select cust
Dim londonC2 = From cust In customers
Where cust.City = "London" Or cust.City = "Paris"
Select cust
'<Snippet3>
Dim londonCusts1 = From cust In customers
Where cust.City = "London"
Order By cust.Name Ascending
' ...
'</Snippet3>
'<Snippet4>
Dim londonCusts2 = From cust In customers
Where cust.City = "London"
Order By cust.Name Ascending
Select cust
'</Snippet4>
'<Snippet5>
Dim londonCusts3 = From cust In customers
Where cust.City = "London"
Order By cust.Name Ascending
Select cust.Name
'</Snippet5>
'<Snippet6>
Dim londonCusts4 = From cust In customers
Where cust.City = "London"
Order By cust.Name Ascending
Select Name = cust.Name, Phone = cust.Phone
For Each londonCust In londonCusts4
Console.WriteLine(londonCust.Name & " " & londonCust.Phone)
Next
'</Snippet6>
'<Snippet8>
Dim londonCusts5 = From cust In customers
Where cust.City = "London"
Order By cust.Name Ascending
Select New NamePhone With {.Name = cust.Name,
.Phone = cust.Phone}
'</Snippet8>
Dim students = GetStudents()
'<Snippet9>
Dim vowels() As String = {"A", "E", "I", "O", "U"}
Dim vowelNames = From student In students, vowel In vowels
Where student.Last.IndexOf(vowel) = 0
Select Name = student.First & " " &
student.Last, Initial = vowel
Order By Initial
For Each vName In vowelNames
Console.WriteLine(vName.Initial & ": " & vName.Name)
Next
'</Snippet9>
'<Snippet10>
Dim vowelNames2 = From student In students
Join vowel In vowels
On student.Last(0) Equals vowel
Select Name = student.First & " " &
student.Last, Initial = vowel
Order By Initial
'</Snippet10>
'<Snippet11>
Dim studentsByYear = From student In students
Select student
Group By year = student.Year
Into Classes = Group
For Each yearGroup In studentsByYear
Console.WriteLine(vbCrLf & "Year: " & yearGroup.year)
For Each student In yearGroup.Classes
Console.WriteLine(" " & student.Last & ", " & student.First)
Next
Next
'</Snippet11>
'<Snippet12>
Dim studentsByYear2 = From student In students
Select student
Order By student.Year, student.Last
Group By year = student.Year
Into Classes = Group
'</Snippet12>
End Sub
'<Snippet7>
Public Class NamePhone
Public Name As String
Public Phone As String
' Additional class elements
End Class
'</Snippet7>
' Function GetCustomers returns a list of Customer objects.
Function GetCustomers() As IEnumerable(Of Customer)
Dim customerList As New System.Collections.Generic.List(Of Customer)
Dim customer0 As New Customer With {.Name = "Michael",
.City = "Tucker",
.State = "Junior",
.ID = 123}
Dim customer1 As New Customer With {.Name = "Svetlana",
.City = "Omelchenko",
.State = "Senior",
.ID = 456}
Dim customer2 As New Customer With {.Name = "Michiko",
.City = "Osada",
.State = "Senior",
.ID = 789}
Dim customer3 As New Customer With {.Name = "Sven",
.City = "Mortensen",
.State = "Freshman"}
Dim customer4 As New Customer With {.Name = "Hugo",
.City = "Garcia",
.State = "Junior"}
Dim customer5 As New Customer With {.Name = "Cesar",
.City = "Garcia",
.State = "Freshman",
.ID = 890}
Dim customer6 As New Customer With {.Name = "Fadi",
.City = "Fakhouri",
.State = "Senior",
.ID = 765}
customerList.Add(customer0)
customerList.Add(customer1)
customerList.Add(customer2)
customerList.Add(customer3)
customerList.Add(customer4)
customerList.Add(customer5)
customerList.Add(customer6)
'customerList.Add(customer7)
'customerList.Add(customer8)
'customerList.Add(customer9)
'customerList.Add(customer10)
Return customerList
End Function
Public Class Customer
Private _name, _city, _state, _title As String
Private _id As Integer
Public Address As AddressClass
Public Phone As String
Public OrderNumbers() As Integer
Public OrderNumber As Integer
Sub New()
End Sub
Sub New(ByVal newName As String)
_name = newName
End Sub
Property Name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
Property City() As String
Get
Return _city
End Get
Set(ByVal value As String)
_city = value
End Set
End Property
Property State() As String
Get
Return _state
End Get
Set(ByVal value As String)
_state = value
End Set
End Property
Property Title() As String
Get
Return _title
End Get
Set(ByVal value As String)
_title = value
End Set
End Property
Property ID() As Integer
Get
Return _id
End Get
Set(ByVal value As Integer)
_id = value
End Set
End Property
End Class
Class AddressClass
Public City, State As String
End Class
' Call DisplayList to see the names of the students in the list.
' You can expand this method to see other student properties.
Sub DisplayList(ByVal studentCol As List(Of Student))
' Dim studentCol = GetStudents()
For Each st As Student In studentCol
Console.WriteLine("First Name: " & st.First)
Console.WriteLine(" Last Name: " & st.Last)
Console.WriteLine()
Next
End Sub
' Function GetStudents returns a list of Student objects.
Function GetStudents() As IEnumerable(Of Student)
Dim studentList As New System.Collections.Generic.List(Of Student)
Dim student0 As New Student With {.First = "Michael",
.Last = "Tucker",
.Year = "Junior",
.Rank = 10}
Dim student1 As New Student With {.First = "Svetlana",
.Last = "Omelchenko",
.Year = "Senior",
.Rank = 2}
Dim student2 As New Student With {.First = "Michiko",
.Last = "Osada",
.Year = "Senior",
.Rank = 7}
Dim student3 As New Student With {.First = "Sven",
.Last = "Mortensen",
.Year = "Freshman",
.Rank = 53}
Dim student4 As New Student With {.First = "Hugo",
.Last = "Garcia",
.Year = "Junior",
.Rank = 16}
Dim student5 As New Student With {.First = "Cesar",
.Last = "Garcia",
.Year = "Freshman",
.Rank = 4}
Dim student6 As New Student With {.First = "Fadi",
.Last = "Fakhouri",
.Year = "Senior",
.Rank = 72}
Dim student7 As New Student With {.First = "Hanying",
.Last = "Feng",
.Year = "Senior",
.Rank = 11}
Dim student8 As New Student With {.First = "Debra",
.Last = "Garcia",
.Year = "Junior",
.Rank = 41}
Dim student9 As New Student With {.First = "Lance",
.Last = "Tucker",
.Year = "Junior",
.Rank = 60}
Dim student10 As New Student With {.First = "Terry",
.Last = "Adams",
.Year = "Senior",
.Rank = 6}
studentList.Add(student0)
studentList.Add(student1)
studentList.Add(student2)
studentList.Add(student3)
studentList.Add(student4)
studentList.Add(student5)
studentList.Add(student6)
studentList.Add(student7)
studentList.Add(student8)
studentList.Add(student9)
studentList.Add(student10)
Return studentList
End Function
' Each student has a first name, a last name, a class year, and
' a rank that indicates academic ranking in the student body.
Public Class Student
Private _first As String
Public Property First() As String
Get
Return _first
End Get
Set(ByVal value As String)
_first = value
End Set
End Property
Private _last As String
Public Property Last() As String
Get
Return _last
End Get
Set(ByVal value As String)
_last = value
End Set
End Property
Private _year As String
Public Property Year() As String
Get
Return _year
End Get
Set(ByVal value As String)
_year = value
End Set
End Property
Private _rank As Integer
Public Property Rank() As Integer
Get
Return _rank
End Get
Set(ByVal value As Integer)
_rank = value
End Set
End Property
End Class
End Module