2013-04-30 74 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