数据:
G1 | TINA AM | 22 | CT | 3
G2 | TINA AM | 22 | TLC | 3
G3 | TINA AM | 22 | TLC | 3
G4 | TINA AM | 10 | CT | 2
想要实现的效果:
list1:
G1 | TINA AM | 22 | CT | 3
list2:
G2 | TINA AM | 22 | TLC | 3
G3 | TINA AM | 22 | TLC | 3
list3:
G4 | TINA AM | 10 | CT | 2
部分代码如下:
public class CommodityInfo
{
public string GateNo { get; set; }
public string NozzleStyle { get; set; }
public string NozzleSize { get; set; }
public string NozzleType { get; set; }
public int HeatreCount { get; set; }
}
private void button1_Click(object sender, EventArgs e)
{
List<CommodityInfo> personList = new List<CommodityInfo>();
personList.Add(new CommodityInfo() { GateNo = "G1", NozzleStyle = "TINA AM", NozzleSize = "22", NozzleType = "CT", HeatreCount = 3 });
personList.Add(new CommodityInfo() { GateNo = "G2", NozzleStyle = "TINA AM", NozzleSize = "22", NozzleType = "TLC", HeatreCount = 3 });
personList.Add(new CommodityInfo() { GateNo = "G3", NozzleStyle = "TINA AM", NozzleSize = "22", NozzleType = "TLC", HeatreCount = 3 });
personList.Add(new CommodityInfo() { GateNo = "G4", NozzleStyle = "TINA AM", NozzleSize = "10", NozzleType = "CT", HeatreCount = 2 });
}
personList.GroupBy(t=>$"{t.NozzleType}{t.HeatreCount }" )
.Dictionary(t=>t.Key,t=>t.ToArray();)
问题已解决,谢谢🙏
看你这例子也不是分组啊,不是筛选吗?
姑且看成分组,比如按照NozzleSize 和NozzleType 分组,
var groupNozzleSize = personList.groupby(new{param1=NozzleSize ,param2=NozzleType});
感谢回复,问题已解决🙏
var list1=personList.where(e=>e.NozzleType.Equals("CT")&&e.HeatreCount==3 );
var list2=personList.where(e=>e.NozzleType.Equals("TLC")&&e.HeatreCount==3 );
var list3=personList.where(e=>e.NozzleType.Equals("CT")&&e.HeatreCount==2 );
感谢回复,问题已解决🙏