Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用公共属性合并IEnumerable类型的列表';s值_C#_List_Ienumerable - Fatal编程技术网

C# 使用公共属性合并IEnumerable类型的列表';s值

C# 使用公共属性合并IEnumerable类型的列表';s值,c#,list,ienumerable,C#,List,Ienumerable,我有6个IEnumerable类型列表。 SalesSummaryDAO如下所示 public class SalesSummaryDAO { public int Year {get;set;} public decimal? Cost {get;set;} } 清单如下: IEnumerable<SalesSummaryDAO> FabricCost = getFabricCostDataByYear(); IEnume

我有6个
IEnumerable
类型列表。 SalesSummaryDAO如下所示

  public class SalesSummaryDAO {

    public int Year {get;set;}

    public decimal? Cost {get;set;}

}
清单如下:

        IEnumerable<SalesSummaryDAO> FabricCost = getFabricCostDataByYear();
        IEnumerable<SalesSummaryDAO> AccessoryCost = getAccessoryCostDataByYear();
        IEnumerable<SalesSummaryDAO> FOBRevenue = getFobRevenueDataByYear();
        IEnumerable<SalesSummaryDAO> StockCost = getStockLotsCostDataByYear();
        IEnumerable<SalesSummaryDAO> StockRevenue = getStockLotsRevenueDataByYear();
        IEnumerable<SalesSummaryDAO> FixedCost = getFixedCost();
IEnumerable FabricCost=getFabricCostDataByEAR();
IEnumerable AccessoryCost=GetAccessoryCostDataByEAR();
IEnumerable FOBRevenue=getfobrevenuedatabyear();
IEnumerable StockCost=GetStockLotsCostDataByEAR();
IEnumerable StockRevenue=GetStockLotsRevenueDataByEAR();
IEnumerable FixedCost=getFixedCost();
如您所见,每个列表都包含一组SalesSummaryDAO类型的对象。我需要做的是,我想用这些列表计算每年的净利润。例如,2015年的净利润计算如下:

净利润(2015)=FOBRevenue(2015)+库存收入(2015)-制造成本(2015)-配件成本(2015)-库存成本(2015)-固定成本(2015)


在计算了每年的净利润后,我想将它们存储在另一个
IEnumerable
列表中,其中成本变量包含每年的净利润

您可以使用分组:

var resultList = FabricCost.Concat(AccessoryCost)  // append together
                           .Concat(FOBRevenue)     // append together
                           .Concat(StockCost)      // append together
                           .Concat(StockRevenue)   // append together
                           .Concat(FixedCost)      // append together 
                           .GroupBy(x => x.Year)   // group by year
                           .Select(g => new SalesSummaryDAO ()
                            {
                              Year = g.Key,
                              Cost = g.Sum(x => x.Cost)
                            }) // project to SalesSummaryDAO 
                           .ToList(); // make it a real list!

这将按年度对所有列表进行分组并汇总-只需将要减去的项目设置为负成本(例如织物成本)。

您有列表,您有公式,那么您的问题到底是什么?我想您只想对这些数据使用一个列表,而不是六个列表。我说的对吗?@ChitanyaGadkari似乎你还没有清楚地理解这个问题。不管怎样,由于下面的答案,我找到了解决方案