2016-12-24 35 views
-3

我有以下的代碼,我用它來組對象(收入)每月的列表,並返回一個字典如下C#如何通過周組列表項

List<Income> allIncome = GetAllIncome(); 
     Dictionary<string, int> monthlyIncome = allIncome.GroupBy(i => i.DateCreated.Month) 
      .ToDictionary(i => i.Key.ToString(), i=> i.Sum(x => x.Amount)); 
     return monthlyIncome; 

其中Income模型如下

Income: 
    public string Name{get;set;}; 
    public DataTime DateCreated{get;set;} 

我仍然試圖找出如何執行數週。那就是如何將收入項目按周而不是按月分組。任何想法請。

+0

廣告:你可以使用搜索引擎來找到答案...谷歌,雅虎,漫步者,百度,Bing - https://www.bing.com/search?q=c%23+get +周+數+從+日期或https://www.bing.com/search?q=c%23+groupby+week+數字 –

回答