LAMBDA防爆pression得到的细胞垂直包含行的部分 [英] Lambda Expression to get the cells vertically for a section containing rows

查看:168
本文介绍了LAMBDA防爆pression得到的细胞垂直包含行的部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须遍历每个部分,创建细胞行,最终创造出一个表。在这里,每一部分都有行 0 ....ñ和行有细胞说 0,...,N

I have to iterate through each section and create the cells for rows to ultimately create a table. Here each Section has rows 0....n, and Rows have cells say 0...n

例如,如下图所示:

Row 0->   Cell0 | Cell1| Cell2 | Cell3 | Cell4 | Cell5         
Row 1->   Cell0 | Cell1| Cell2 | Cell3 | Cell4 | Cell5      
Row 2->   Cell0 | Cell1| Cell2 | Cell3 | Cell4 | Cell5     
..

我想创建一个lambda EX pression(说):

I want to create a lambda expression (say):

var allColumns = ...........         

要获得所有CELL0的那么所有的电池1的,所有的电池2的等等......这样我就可以在循环迭代,并创建一个表中为每个。要求不希望我去了一行行,但它希望我通过柱走柱(如图中所示的上述细胞,我创建了CELL0首款然后CELL1当时小区2的等,像下面的循环。

To get all Cell0's then all Cell1's, all Cell2's etc... so that I can iterate in loop and create a table for each. The requirement does not want me to go row by row but it wants me to go column by column (cell as illustrated above in the diagram, I create the the cell0's first then cell1's then cell 2's etc, like in the loop below.

foreach(Cell c in allColumns){
    //I want to iterate in this loop and create my cells and rows.    
}

您可以帮给我的λEX pression这一点。

Can you help give me the lambda expression for this.

我想这样做,

var allColumns = Sections.Rows.SelectMany(a=>a.Cells).GroupBy(What should come here).                             

您可以改进或提出一个更好的lambda EX pression保持上面的foreach循环和上面的图示记住。提前致谢。

Can you improve or suggest a better Lambda expression keeping the above foreach loop and illustration above in mind. thanks in advance.

推荐答案

您可以试试这个演示,我已经放在一起,看看它是否适合你(应该放在一个Windows控制台应用程序):

You can try this demo which I had put together and see if it works for you (it should be put in a Windows console application):

        DataTable dt = new DataTable();
        dt.Columns.AddRange(new DataColumn[] { 
               new DataColumn("col1"), 
               new DataColumn("col2"), 
               new DataColumn("col3") });

        dt.Rows.Add("cell0", "cell1", "cell2");
        dt.Rows.Add("cell0", "cell1", "cell2");
        dt.Rows.Add("cell0", "cell1", "cell2");
        dt.Rows.Add("cell0", "cell1", "cell2");

        // writes out the original data
        foreach (DataRow row in dt.Rows)
        {
            foreach (var column in row.ItemArray)
                Console.Write("{0} ", column);

            Console.WriteLine();
        }
        Console.WriteLine();

        // reverses columns and rows
        var result = dt.Columns
                       .Cast<DataColumn>()
                       .Select(column => 
                          dt.AsEnumerable()
                            .Select(row => 
                               row.ItemArray[column.Ordinal].ToString()));

        // writes out the reversed columns and rows
        foreach (var row in result)
        {
            foreach(var column in row)
                Console.Write("{0} ",column);

            Console.WriteLine();
        }

        Console.ReadKey();

这篇关于LAMBDA防爆pression得到的细胞垂直包含行的部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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