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
|
Public Class Form1
'Linq avec le predicate Except......
'j'ai double sciemment le string "above"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim words1 As List(Of String) = New List(Of String) From {"as", "as", "also", "and", "above", "again", "for each", "for each", "and", "as"}
Dim words2 As List(Of String) = New List(Of String) From {"and", "as", "a", "also"}
Dim T3 As List(Of String) = New List(Of String)
T3 = words1.Except(words2, StringComparer.OrdinalIgnoreCase).ToList
ListBox1.DataSource = T3
End Sub
'Linq avec le predicate RemoveAll combine à ForEach raccourci..
'Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
' Dim words1 As List(Of String) = New List(Of String) From {"as", "as", "also", "and", "above", "again", "for each", "for each", "and", "as"}
' Dim words2 As List(Of String) = New List(Of String) From {"and", "as", "a", "also"}
' Dim T3 As List(Of String) = New List(Of String)
' 'Comparing the two lists and gettings common elements.
' T3 = words1.Intersect(words2, StringComparer.OrdinalIgnoreCase).ToList
' ListBox2.DataSource = T3
'End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim words1 As List(Of String) = New List(Of String) From {"as", "as", "also", "and", "above", "again", "for each", "for each", "and", "as"}
Dim words2 As List(Of String) = New List(Of String) From {"and", "as", "a", "also"}
words2.ForEach(Function(p) words1.RemoveAll(Function(x) x = p))
ListBox2.DataSource = words1
End Sub
End Class |