<i id='qTha8'><tr id='qTha8'><dt id='qTha8'><q id='qTha8'><span id='qTha8'><b id='qTha8'><form id='qTha8'><ins id='qTha8'></ins><ul id='qTha8'></ul><sub id='qTha8'></sub></form><legend id='qTha8'></legend><bdo id='qTha8'><pre id='qTha8'><center id='qTha8'></center></pre></bdo></b><th id='qTha8'></th></span></q></dt></tr></i><div id='qTha8'><tfoot id='qTha8'></tfoot><dl id='qTha8'><fieldset id='qTha8'></fieldset></dl></div>

<legend id='qTha8'><style id='qTha8'><dir id='qTha8'><q id='qTha8'></q></dir></style></legend>

<tfoot id='qTha8'></tfoot>

<small id='qTha8'></small><noframes id='qTha8'>

      • <bdo id='qTha8'></bdo><ul id='qTha8'></ul>

      1. 使用 SUM 和 ORDER BY 进行 Linq 查询

        时间:2023-06-05

          <tbody id='RHdnk'></tbody>

          <small id='RHdnk'></small><noframes id='RHdnk'>

            <bdo id='RHdnk'></bdo><ul id='RHdnk'></ul>
              <legend id='RHdnk'><style id='RHdnk'><dir id='RHdnk'><q id='RHdnk'></q></dir></style></legend>

                <i id='RHdnk'><tr id='RHdnk'><dt id='RHdnk'><q id='RHdnk'><span id='RHdnk'><b id='RHdnk'><form id='RHdnk'><ins id='RHdnk'></ins><ul id='RHdnk'></ul><sub id='RHdnk'></sub></form><legend id='RHdnk'></legend><bdo id='RHdnk'><pre id='RHdnk'><center id='RHdnk'></center></pre></bdo></b><th id='RHdnk'></th></span></q></dt></tr></i><div id='RHdnk'><tfoot id='RHdnk'></tfoot><dl id='RHdnk'><fieldset id='RHdnk'></fieldset></dl></div>

                  <tfoot id='RHdnk'></tfoot>
                • 本文介绍了使用 SUM 和 ORDER BY 进行 Linq 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我有一个名为 Hit 的 (C#) 类,它具有 ItemID (int) 和 Score (int) 属性.我跳过其余的细节以保持简短.现在在我的代码中,我有一个巨大的列表,我需要在该列表上执行以下选择(进入一个新列表):我需要为每个单独的 Hit.ItemID 获取所有 Hit.Score 的总和,按分数排序.所以如果我在原始列表中有以下项目

                  I have a (C#) class called Hit with an ItemID (int) and a Score (int) property. I skip the rest of the details to keep it short. Now in my code, I have a huge List on which I need to do the following select (into a new List): I need to get the sum of all Hit.Score's for each individual Hit.ItemID, ordered by Score. So if I have the following items in the original list

                  ItemID=3, Score=5
                  ItemID=1, Score=5
                  ItemID=2, Score=5
                  ItemID=3, Score=1
                  ItemID=1, Score=8
                  ItemID=2, Score=10
                  

                  结果列表应包含以下内容:

                  the resulting List should contain the following:

                  ItemID=2, Score=15
                  ItemID=1, Score=13
                  ItemID=3, Score=6
                  

                  有人可以帮忙吗?

                  推荐答案

                  var q = (from h in hits
                      group h by new { h.ItemID } into hh
                      select new {
                          hh.Key.ItemID,
                          Score = hh.Sum(s => s.Score)
                      }).OrderByDescending(i => i.Score);
                  

                  这篇关于使用 SUM 和 ORDER BY 进行 Linq 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:List&lt;int&gt; 中 int 的总和范围 下一篇:LINQ 和溢出异常?

                  相关文章

                  最新文章

                  <legend id='XZ5J2'><style id='XZ5J2'><dir id='XZ5J2'><q id='XZ5J2'></q></dir></style></legend>

                  <tfoot id='XZ5J2'></tfoot>

                  1. <i id='XZ5J2'><tr id='XZ5J2'><dt id='XZ5J2'><q id='XZ5J2'><span id='XZ5J2'><b id='XZ5J2'><form id='XZ5J2'><ins id='XZ5J2'></ins><ul id='XZ5J2'></ul><sub id='XZ5J2'></sub></form><legend id='XZ5J2'></legend><bdo id='XZ5J2'><pre id='XZ5J2'><center id='XZ5J2'></center></pre></bdo></b><th id='XZ5J2'></th></span></q></dt></tr></i><div id='XZ5J2'><tfoot id='XZ5J2'></tfoot><dl id='XZ5J2'><fieldset id='XZ5J2'></fieldset></dl></div>
                      • <bdo id='XZ5J2'></bdo><ul id='XZ5J2'></ul>
                    1. <small id='XZ5J2'></small><noframes id='XZ5J2'>