在程序中有两表(不是数据库是List中的表):
表1:
1   a
1   b
2   b表2:
1   a
1   b
2   b
4   c
如何得到两表之差?:
得到表:
4   c

解决方案 »

  1.   

    使用循环~~
    if(list1[i]==list[i])
    {
      remove()
    }
      

  2.   

    遍历两个表中行少的表,把行少的表中的每一行从另一个表中remove()掉就可以了~
      

  3.   

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.Collections;
    using System.IO;namespace CSharpTest
    {    class A
        {
            public int nu;
            public string ch;
            public A(int a, string c)
            {
                nu = a;
                ch = c;
            }
        }    class B
        {        static void Main()
            {
                List<A> list1 = new List<A>();
                list1.Add(new A(1, "a"));
                list1.Add(new A(1, "b"));
                list1.Add(new A(2, "b"));
                List<A> list2 = new List<A>();
                list2.Add(new A(1, "a"));
                list2.Add(new A(1, "b"));
                list2.Add(new A(2, "b"));
                list2.Add(new A(4, "c"));
                foreach (A m in list2)
                {
                    if (!exists(list1, m))
                        Console.WriteLine("{0} {1}", m.nu, m.ch);
                }
            }        static bool exists(List<A> list, A a)
            {
                foreach (A b in list)
                {
                    if (b.ch == a.ch && b.nu == a.nu) return true;
                }
                return false;
            }
        }}