VB.NET Remove duplicate numbers/records from an array
Suppose array has series of numbers, if user wants to extract/find duplicated number in an array.
Here is the Logic.
Private Shared Sub RemoveDuplicateNumbersInArray()
Dim a As Integer() = New Integer() {10, 20, 10, 30, 30, 20, _
40, 40, 12, 14, 12, 14}
Dim query =
a = New Integer(query.Count() - 1) {}
For i As Integer = 0 To query.Count() - 1
a(i) = query.ElementAt(i).Key
Next
For Each i As Integer In a
Console.WriteLine(i)
Next
End Sub
Dim a As Integer() = New Integer() {10, 20, 10, 30, 30, 20, _
40, 40, 12, 14, 12, 14}
Dim query =
a = New Integer(query.Count() - 1) {}
For i As Integer = 0 To query.Count() - 1
a(i) = query.ElementAt(i).Key
Next
For Each i As Integer In a
Console.WriteLine(i)
Next
End Sub
Note : 1.Group each number by that number, so that duplicates will be under same group.
2.if any group has more than one element
query.Count() returns unique elements count.
3. Then assign this values to existing array.
Input : int[] a = new int[] { 10, 20, 100, 100, 100, 10, 30, 20, 40, 50, 12, 14 };
Output:10 20 100 30 40 50 12 14
i.e 10,20,100 repeated more than once . so these are extra values removed from the array.
Input: int[] a = new int[] { 10, 20, 10,30, 30, 20, 40, 40, 12, 14,12,14 };
Output: 10 20 30 40 12 14
i.e 10 ,20,30,40,12,14 numbers repeated more than one time in an array a.
Tags:
2.if any group has more than one element
query.Count() returns unique elements count.
3. Then assign this values to existing array.
Input : int[] a = new int[] { 10, 20, 100, 100, 100, 10, 30, 20, 40, 50, 12, 14 };
Output:10 20 100 30 40 50 12 14
i.e 10,20,100 repeated more than once . so these are extra values removed from the array.
Input: int[] a = new int[] { 10, 20, 10,30, 30, 20, 40, 40, 12, 14,12,14 };
Output: 10 20 30 40 12 14
i.e 10 ,20,30,40,12,14 numbers repeated more than one time in an array a.
Tags:
VB.NEt Remove duplicate numbers/records from an array,vb.net Remove duplicate records from an array,vb.net get unique elements array,vb.net get unique array,IGrouping LINQ,LINQ Count,LINQ
Select on IGrouping,vb.net Find only Duplicate Values in an Array using
LINQ
No comments:
Post a Comment