VB.Net 如何過濾重複的陣列元素 (VB.NET)
' 方法 1 Private Sub Button1_Click(ByVal s As Object, ByVal e As EventArgs) Handles Button1.Click
Dim ary() As Integer = {1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3} ' 使用預設的相等比較子來比較值,以便從序列傳回獨特的項目。
For Each i As Integer In ary.Distinct.ToArray()
MessageBox.Show(i) Next
End Sub
' 方法 2 Private Sub Button2_Click(ByVal s As Object, ByVal e As EventArgs) Handles Button2.Click Dim ary() As Integer = {1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3}'IEnumerable 泛型介面
Dim ienum As IEnumerable(Of Integer) = ary ' Enumerable類別.Distinct 方法移除重複項目的序列
For Each i As Integer In ienum.Distinct MessageBox.Show(i) Next
End Sub
引用http://itgroup.blueshop.com.tw/HammerChou/PowerHammer?n=convew&i=3452
如有錯誤 歡迎指正