2017-01-13 3 views
1
public class Info 
{ 
    public List<string> Projects { get; set; } 
    public List<string> Schools { get; set; } 
    public List<string> Locations { get; set; } 
    public List<string> Interests { get; set; } 
    public List<string> Hobbies { get; set; } 
} 

からすべてのリストを交差する:list1.Select(a => a.Projects).Intersect(list2.Select(b => b.Projects));最も簡単な方法はあなただけでこれを行うことができ、2つのリストを交差する2つの異なるオブジェクト

しかし、あなたは一般的な文字列を持つかもしれない第三の目的を持っているしたい場合はどのような最初の2つのオブジェクトから考えてみましょう。

+1

あなたは1日から、最後のリストにさらに移動すると、あなたが最終的なソリューションを取得する交差をやって継続できないようにどのような。 'ProjectList.Intersect(SchoolList).Intersect(LocationList).Intersect(InterestList).Intersect(HobbyList)' –

+0

@MrinalKambojは何も私を妨げませんが、私はonlinerでおそらくそれを行うことができると思いましたか? –

+0

それはまた1つのライナーではないだろう –

答えて

2

私は考えることができる最も簡単な解決策はCascading Intersectionです:

var result = Projects.Intersect(Schools) 
        .Intersect(Locations) 
        .In‌​tersect(Interests​) 
        .Intersect(Hobbies) 
        .ToList(); 
関連する問題