如何与Linq ....? [英] How to with Linq....?

查看:89
本文介绍了如何与Linq ....?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的数据表:



I have a datatable like this:

column1 | column2 | column3 | column4   | column5
-------------------------------------------------
TypeABC | Jan     | 2012    | location1 | 14
TypeABC | Jan     | 2012    | location2 | 19
TypeABC | Feb     | 2012    | location1 | 17
TypeABC | Feb     | 2012    | location2 | 55





我想要一个像这样的数据表使用linq:





I want a datatable like this one using linq:

Column1 | Column2 | Column3 | Column4(location1) | Column5(location2)
---------------------------------------------------------------------
TypeABC | Jan     | 2012    | 14                 | 19
TypeABC | Feb     | 2012    | 17                 | 55





任何建议都表示赞赏。



谢谢。



Any suggestion is appreciated.

Thank you.

推荐答案

我的建议是查看 Enumerable.GroupBy [ ^ ]扩展方法。然后,您可以使用 Enumerable.Select [ ^ ]和 Enumerable.SelectMany [ ^ ]来操纵结果形成你想要的形式。



顺便说一句:花一点时间让你的问题更清晰,更容易阅读可以让人们更愿意回答你的问题。对于您用来表示表格的布局,< pre>标签是你的朋友,因为它们使用固定宽度的字体显示。
My suggestion would be to look into the Enumerable.GroupBy[^] extension method. You can then use Enumerable.Select[^] and Enumerable.SelectMany[^] to manipulate the results into the form you want.

As an aside: spending a little time to make your question clearer and easier to read can make people more willing to answer your questions. For layouts like the one you''ve used to represent your tables, <pre> tags are your friend, as they are shown using a fixed-width font.


这篇关于如何与Linq ....?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆