LINQ: Distinct values

前端 未结 7 1127
一生所求
一生所求 2020-11-22 16:29

I have the following item set from an XML:

id           category

5            1
5            3
5            4
5            3
5            3
<
7条回答
  •  隐瞒了意图╮
    2020-11-22 16:53

    // First Get DataTable as dt
    // DataRowComparer Compare columns numbers in each row & data in each row
    
    IEnumerable Distinct = dt.AsEnumerable().Distinct(DataRowComparer.Default);
    
    foreach (DataRow row in Distinct)
    {
        Console.WriteLine("{0,-15} {1,-15}",
            row.Field(0),
            row.Field(1)); 
    }
    

提交回复
热议问题