C#对List列表中的对象分组对象类定义如下:
public class PipeDetail
{
private string systemType;
public string SystemType
{
set { systemType = value; }
get { return systemType; }
}
private string material;
public string Material
{
set { material = value; }
get { return material; }
}
private double diameter;
public double Diameter
{
set { diameter = value; }
get { return diameter; }
}
private double length;
public double Length
{
set { length = value; }
get { return length; }
}
groupby分组public PipeDetail(string systemType, string material, double diam, double len)
{
this.systemType = systemType;
this.material = material;
this.length = len;
this.diameter = diam;
}
}
List列表定义:
private List<PipeDetail> details = new List<PipeDetail>();
遍历向details中添加数据
按照SystemType分组
IEnumerable<IGrouping<string, PipeDetail>> query = details.GroupBy(dt => dt.SystemType, dt => dt);        foreach (IGrouping<string, PipeDetail> info in query)
{
List<PipeDetail> pd = info.ToList<PipeDetail>();
// pd.Sort(new DiameterComparer());
foreach (PipeDetail temp in pd)
{......}
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。