大佬教程收集整理的这篇文章主要介绍了LINQ Group由VB.Net中的多个属性组成,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
dim lFinal={new with {.Year=2010,.Month=6,.Value1=0,.Value2=0},new with {.Year=2010,.Value1=2,.Value2=1},.Month=7,.Value1=3,.Value2=4},.Month=8,new with {.Year=2011,.Month=1,.Value2=2},.Value2=0}} Dim lFinal2 = From el In lFinal Group el By Key = new with {el.Year,el.Month} Into Group SELEct New With {.Year = Key.Year,.Month=Key.Month,.Value1 = Group.Sum(Function(X) x.Value1),.Value2 = Group.Sum(Function(X) x.Value2)} lFinal.Dump() lFinal2.Dump()
lFinal列表有6个项目,我想要lFinal2有4个项目:2010-6和2011-1应该组合.
提前致谢.
= Group el By Key = new with {el.Year,el.Month}
隐式对象不知道要检查年份和月份(只是因为它具有属性并不意味着在与其他对象进行比较时检查它们).
所以你可能需要做更多的事情:
= Group el By Key = new CustomKey() { Year = el.Year,Month = el.Month }; public class CustomKey{ int Year { get; set; } int Month { get; set; } public override bool Equals(obj A) { var key (CustomKey)A; return key.Year == this.Year && key.Month == this.Month; } }
以上是大佬教程为你收集整理的LINQ Group由VB.Net中的多个属性组成全部内容,希望文章能够帮你解决LINQ Group由VB.Net中的多个属性组成所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。