日期:2014-05-18  浏览次数:21114 次

泛型:剔除元素
从num中,剔除a与b 所有的元素,然后把剩下的元素依次显示在单元格(1,20)里面

C# code
    
List<int> num = new List<int>(10){ 0, 1,2, 3, 4, 5, 6, 7, 8, 9 };
List<int> a = new List<int>(3){ 2,3,6 };
List<int> b = new List<int>(3){ 0,3,5 };

num.Except(a.Union(b));

foreach (int item in num)
{
      DataGrid.Cell(1, 20).Text = num.ToString();
}




上面这样写,错在哪里呢?谢谢

------解决方案--------------------
探讨

引用:

C# code

List<int> num = new List<int>(10) { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
List<int> a = new List<int>(3) { 2, 3, 6 };
List<int> b = new List<int>(3) { 0, 3, 5 ……


哦,只显示了一个数……

------解决方案--------------------
for (int i = 0; i < result.Count; i++)
{
f.ListGrid.Cell(r, 20).Text = result[i].ToString();
}
这个都写出来了,哪怕是傻子也会举一反三了吧。
for (int i = 0; i < result.Count - 1; i++)
{
f.ListGrid.Cell(r, 20).Text = f.ListGrid.Cell(r, 20).Text + result[i].ToString() + ",";
}
f.ListGrid.Cell(r, 20).Text = f.ListGrid.Cell(r, 20).Text + result[result.Count - 1].ToString();
如果你真的是在“学习”的话,就把这代码的意思看看清楚。