对象类定义如下:
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; }
}
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)
{......}
}