2014-05-22 37 views
0

我想找到一個僱員和經理b/w數組的關係。如何找到關係b/w兩個集合c#

我的代碼,如:

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; 
} 

任何幫助嗎?

回答

0

這聽起來像你正在尋找這樣的事情(假設ListPeople()是返回的人集合的方法,他們中堂屬性Name):

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

這是返回null – ManzoorPK

+0

其實我需要一個關係b/w僱員和經理第一個功能有所有的經理和在下拉我顯示的僱員,所以如果僱員1選擇查找人的方法應該需要找出所有屬於僱員的經理1 – ManzoorPK

+0

您可以指定您的架構對象和他們通過哪些財產相關? – RePierre