comparing two List<>

后端 未结 4 1089
栀梦
栀梦 2021-01-24 06:16

i have gridview control with a checkbox on it

When i hit on save button i able to find the checkbox which have been checked and i able to do it so far so good but the pr

4条回答
  •  爱一瞬间的悲伤
    2021-01-24 07:04

    It sounds like what you need is set operations. You have a few choices:

    .NET 4.0 - HashSet

    http://msdn.microsoft.com/en-us/library/bb359438.aspx

    .NET 3.5 - Linq extensions

    The Linq to Objects extensions contains some set operations like Intersect and Union. http://msdn.microsoft.com/en-us/library/system.linq.enumerable.aspx

    .NET 2.0 - SetList

    In 2.0 you'll need to hand-roll something like the following SetList class. http://csharptest.net/browse/src/Library/Collections/SetList.cs (online-help)

    To use SetList:

    SetList listFromDB = new SetList(EmployeeListFromDB);
    SetList selectedEmployee = new SetList(MySelectedEmployee);
    
    SetList removed = listFromDB.SubtractSet(selectedEmployee);
    SetList added = selectedEmployee.SubtractSet(listFromDB);
    

    Note: Employee must implement IComparable, or you should write an IComparer and provide it to the SetList constructor calls above.

提交回复
热议问题