2013-04-30 71 views
1

我有這樣的對象:排序包含列表對象的列表每個排序依據

public class humanInfo 
{ 
    public string m_Name { get;set; } 

    public List<HumanAttributes> m_ListHumanAttributes { get; set;} 
} 

我想基礎上,Age屬性,它位於每個人的屬性列表進行排序這個列表。

humanList = humanList.OrderBy(/*How am I gonna do this?*/); 

我試圖達到使用x => x.m_ListHumanAttributes.All(),例如所有項目,但我是一個有點無能,我怎麼可能會繼續。任何人都有一個好主意?

編輯

這裏有一個想法HumanAttributes類可能是如何工作的:

public class HumanAttributes 
{ 
    public int m_HumanAttributesID {get;set;} 

    public Sex m_HumanAttributeSex {get;set;} 

    public int m_HumanAge {get;set;} 

    public decimal m_HumanHeight {get;set;} 
} 
+0

我們可以看看'HumanAttributes '? – 2013-04-30 19:52:56

+0

也許'x => x.Age'? – Tim 2013-04-30 19:54:13

回答

3

假設HumanAttributes具有Name和Value屬性:

humanList.OrderBy(h=>h.ListHumanAttributes.First(a=>a.Name=="Age").Value); 
+1

+1我會使用'DefaultOrFirst',爲處理沒有定義「年齡」屬性的人類提供空間/機會 – 2013-04-30 19:55:09

+0

有趣!我會試試這個,謝謝 – hsim 2013-04-30 19:55:28

+0

假設我想按字母順序排列它們的名字,我怎麼能繼續? – hsim 2013-04-30 19:56:49