3
 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();

同じ結果を得る他の方法???

ここで:booksは、本オブジェクトのコレクション、つまりIEnumerableです。

ありがとう

4

1 に答える 1

13

代替ソリューション-SelectMany必要なプロパティの配列から:

var lstfinal = books.SelectMany(b => new [] { b.CreatedById, b.ModifiedById })
                    .Distinct();

または、書籍コレクションを2回列挙します。Union重複を除外するので、呼び出す必要はありませんDistinct(私はこのようにします):

var lstfinal = books.Select(b => b.CreatedById)
                    .Union(books.Select(b => b.ModifiedById));
于 2013-02-27T13:53:06.750 に答える