none
Distinct Values into ObservableCollection(Of Integer) RRS feed

  • Question

  • I have a list I want to populate with INtegers (MyList = New ObservableCollection(Of Integer)

    I have a set of DataTable Rows that I want to populate my list from. What I want are all the distinct ID's from my DataTable rows added to MyList. What I'm trying to avoid is do a For Loop and adding to MyList, like this:

    For Each row in MyRows

    MyList.Add(row.ID)

    Next

    I'm trying to use LINQ so I can do it one line of code, but can't seem to get the syntax right. Something like:

    MyList.Add((From r in MyRows Select r.ID).Distinct)

    But when use the above I get the error:

    Value of type 'System.Collections.Generic.IEnumerable(Of Object)' cannot be converted to 'Integer'

     

     

    Monday, March 14, 2011 5:27 PM

Answers

All replies