var userIds = books.Select( i => new{i.CreatedById,i.ModifiedById}).Distinct();
var lst = from i in userIds select i.CreatedById;
var lst1 = from i in userIds select i.ModifiedById;
var lstfinal = lst.Concat(lst1).Distinct();
any other way to get same result???
here: books is collection of book objects i.e. IEnumerable.
thanks
Alternative solution - SelectMany
from array of required properties:
var lstfinal = books.SelectMany(b => new [] { b.CreatedById, b.ModifiedById })
.Distinct();
Or enumerating books collection twice. Union
excludes duplicates, so you don't need to call Distinct
(I'd go this way):
var lstfinal = books.Select(b => b.CreatedById)
.Union(books.Select(b => b.ModifiedById));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With