我在List<>
中添加了一堆不同的零件,其中一些零件可能具有相同的零件号和相同的长度。如果他们具有相同的零件编号和相同的长度,我需要将这些零件分组来显示。如何在分组时使用Linq查询返回IGrouping
当它们分组时,我需要显示该零件编号以及具有特定长度的零件编号的数量。
我需要知道如何在两个不同的充地产集团,并返回eaigher与List<ICutPart>
一个类型的对象,总的
以下是据我可以得到,我试图返回(IGrouping<int,ICutPart>)sGroup;
,但我在函数体的返回部分出现错误。
如何返回带有Group{List<ICutPart> Parts, Int Total}
的打印对象?
public class CutPart : ICutPart
{
public CutPart() { }
public CutPart(string name, int compID, int partID, string partNum, decimal length)
{
this.Name = name;
this.PartID = partID;
this.PartNumber = partNum;
this.CompID = compID;
this.Length = length;
}
public CutPart(string name, int compID, int partID, string partNum, decimal width, decimal height)
{
this.Name = name;
this.CompID = compID;
this.PartNumber = partNum;
this.PartID = partID;
this.Width = width;
this.Height = height;
this.SF = decimal.Parse(((width/12) * (height/12)).ToString(".0000")); //2dp Number;
}
public string Name { get; set; }
public int PartID { get; set; }
public string PartNumber { get; set; }
public int CompID { get; set; }
public decimal Length { get; set; }
public decimal Width { get; set; }
public decimal Height { get; set; }
public decimal SF { get; set; }
}
public class CutParts : List<ICutPart>
{
public IGrouping<int, ICutPart> GroupParts()
{
var sGroup = from cp in this
group cp by cp.Length into g
select new
{
CutParts = g,
total = g.Count()
};
return (IGrouping<int, ICutPart>)sGroup;
}
public new void Add(ICutPart item)
{
base.Add(item);
}
}
谢谢尼古拉斯。 – 2013-04-07 17:15:37
@ AlumCloud.Com不客气:) – 2013-04-07 17:21:23