1

私はいくつかのクラスのリストオブジェクトタイプを持っています、

class person
{
    public string id { get; set; }
    public string regid { get; set; }
    public string name { get; set; }
}

List<person> pr = new List<person>();
pr.Add(new person { id = "2",regid="2222", name = "rezoan" });
pr.Add(new person { id = "5",regid="5555", name = "marman" });
pr.Add(new person { id = "3",regid="3333", name = "prithibi" });

文字列型のハッシュセット、

HashSet<string> inconsistantIDs = new HashSet<string>();
inconsistantIDs.Add("5");

ここで、inconsistantIDs HashSet の ID を含む pr リストからすべての * regid * のみを取得し、それらを文字列型の別の HashSet に格納したいと考えています。

試してみましたが、inconsistantIDs リストにある ID を持つすべての人しか取得できません (これは単なる例です)。

 HashSet<person> persons = new HashSet<person>(
            pr.Select(p=>p).Where(p=>
                    inconsistantIDs.Contains(p.id)
                ));

誰か助けてくれませんか?

4

2 に答える 2