如何找到关系b / w两个集合c#

时间:2014-05-22 07:37:49

标签: c#-4.0

我正在尝试找到employees和manager b / w数组的关系。

我的代码如下:

public static IEnumerable<LwCiPersonManagers> GetManagerInfo()
{
    var lstManagement = new List<LwCiPersonManagers>
    {
        new LwCiPersonManagers(1, FindPerson("He man").LwCiPersonKey, FindPerson("She Ra").LwCiPersonKey, true),
        new LwCiPersonManagers(2, FindPerson("Lion O").LwCiPersonKey, FindPerson("El Presidente").LwCiPersonKey, true), 
        new LwCiPersonManagers(3, FindPerson("She Ra").LwCiPersonKey, FindPerson("Lion O").LwCiPersonKey, true), 
        new LwCiPersonManagers(4, FindPerson("Jimbo").LwCiPersonKey, FindPerson("Bugs Bunny").LwCiPersonKey, true), 
        new LwCiPersonManagers(5, FindPerson("Popeye").LwCiPersonKey, FindPerson("Bugs Bunny").LwCiPersonKey, true), 
        new LwCiPersonManagers(6, FindPerson("Billy Bob").LwCiPersonKey, FindPerson("Popeye").LwCiPersonKey, true), 
        new LwCiPersonManagers(7, FindPerson("Larry").LwCiPersonKey, FindPerson("Popeye").LwCiPersonKey, true), 
        new LwCiPersonManagers(8, FindPerson("Moe").LwCiPersonKey, FindPerson("Popeye").LwCiPersonKey, true), 
        new LwCiPersonManagers(9, FindPerson("Curly").LwCiPersonKey, FindPerson("Popeye").LwCiPersonKey, true), 
        new LwCiPersonManagers(10, FindPerson("Alvin").LwCiPersonKey, FindPerson("Minnie Mouse").LwCiPersonKey, true), 
        new LwCiPersonManagers(11, FindPerson("Simon").LwCiPersonKey, FindPerson("Minnie Mouse").LwCiPersonKey, true), 
        new LwCiPersonManagers(12, FindPerson("Theodore").LwCiPersonKey, FindPerson("Minnie Mouse").LwCiPersonKey, true), 
        new LwCiPersonManagers(13, FindPerson("Minnie Mouse").LwCiPersonKey, FindPerson("Daisy Duck").LwCiPersonKey, true), 
        new LwCiPersonManagers(14, FindPerson("Daisy Duck").LwCiPersonKey, FindPerson("El Presidente").LwCiPersonKey, true), 
        new LwCiPersonManagers(15, FindPerson("Donald Duck").LwCiPersonKey, FindPerson("Daisy Duck").LwCiPersonKey, true), 
        new LwCiPersonManagers(16, FindPerson("Goofy").LwCiPersonKey, FindPerson("Mickey Mouse").LwCiPersonKey, true), 
        new LwCiPersonManagers(17, FindPerson("Mickey Mouse").LwCiPersonKey, FindPerson("El Presidente").LwCiPersonKey, true)
    };

    return lstManagement;
}

我怎样才能找到正确的记录......

private static LwCiPerson FindPerson(string nameToFind)
{
   LwCiPerson empFound = null;
   //Find the person within the collection returned by .ListPeople()

  return empFound;
}

任何帮助?

1 个答案:

答案 0 :(得分:0)

听起来你正在寻找类似这样的东西(假设ListPeople()是一个返回人物集合的方法,并且他们有一个属性Name):

private static LwCiPerson FindPerson(string nameToFind)
{
    LwCiPerson empFound = ListPeople().FirstOrDefault(p => p.Name == nameToFind);
    return empFound;
}