1

我的输入

   Sore | aye
    A    |   1 
    A    |   2
    A    |   3
    B    |   1
    B    |   2

OutPut:我想将顶部表格排序到下面的树视图中

A
   1 
   2 
   3
B  
   1
   2 
4

1 回答 1

3

假设您有一个Table包含两个属性的类list<string> Sore,并且List<int> aye

public class Table
{
    public String Sore { get; set; }
    public int Aye { get; set; }
}

var table = new List<Table>
                {
                    new Table{  Sore = "A" , Aye = 1},
                    new Table{  Sore = "A" , Aye = 2},
                    new Table{  Sore = "A" , Aye = 3},
                    new Table{  Sore = "B" , Aye = 1},
                    new Table{  Sore = "B" , Aye = 2},
                };
var group = table.GroupBy(q => q.Sore).ToList();
foreach (var g in group)
{
    Debug.WriteLine(g.Key);
    foreach (var i in g)
    {
        Debug.WriteLine("   "+i.Aye);
    }
}

输出将是:

A
   1
   2
   3
B
   1
   2
于 2012-04-28T07:04:47.590 回答