Friday, September 9, 2011

Filtering Arrays Using LINQ

LINQ provide a fast and effective way to filter arrays.

Here is an example on how to get the unique/distinct content of an array:
'An example array
Dim dArray() As Integer = {4, 5, 6, 7, 8, 5}

'Filter by LINQ
'dResult will contain the result.
Dim dResult = (From dNumber As Integer In dArray
               Select dNumber).Distinct

'Display the number of results
MessageBox.Show(dResult.Count)

No comments:

Post a Comment