嗨,我有一个像这样的数据表:
Id Amount 1 Amount 2 Amount 3 1 2 2 2 12 4 6 4 12 6 6 5 22 7 2 1 22 7 2 2
我需要得到这样的数据表:
Id Amount 1 Amount 2 Amount 3 1 2 2 2 12 10 12 9 22 14 4 3
我最初尝试在匿名方法中执行此操作,但我需要将其返回到另一个无法使用匿名方法完成的类.我的第二次尝试是这样做,以便它可以返回:
DataTable ddt = dt.AsEnumerable()
.Sum(g => g.Field<int>("Amount 1"))
.GroupBy(g => new { Col1 = g["ID"] })
.Select(g => g.OrderBy(r => r["ID"]).First())
.CopyToDataTable();
Run Code Online (Sandbox Code Playgroud)
这段代码肯定不会编译但是如果可能的话,任何帮助/建议都会非常感激.我对linq很新.
我最近获得了一个新的项目,将任何给定的字符串转换为1-3个字母的缩写.类似于我必须产生的东西的一个例子是下面给出的字符串可以是任何东西:
switch (string.Name)
{
case "Emotional, Social & Personal": return "ESP";
case "Speech & Language": return "SL";
case "Physical Development": return "PD";
case "Understanding the World": return "UW";
case "English": return "E";
case "Expressive Art & Design": return "EAD";
case "Science": return "S";
case "Understanding The World And It's People"; return "UTW";
}
Run Code Online (Sandbox Code Playgroud)
我想我可以使用string.Split并计算数组中的单词数.然后添加处理特定长度字符串的条件,因为这些句子通常不会长于4个字,但我将遇到的问题是.
关于我可以应用的逻辑的任何建议将非常感激.谢谢