Home > Net >  Shame, recently discovered in linq, a don't understand
Shame, recently discovered in linq, a don't understand

Time:12-17

Recent study linq, is originally wanted to use linq to 2 List to heavy,

His writing is list1. RemoveAll (m=& gt; List2. FindIndex (n=& gt; N.n ame==m.n ame) & gt; 0);
Found only remove 1 row, want to know how to write better,
Then see a take the intersection method, var list=list1. Where ((x, I)=& gt; List2. FindIndex (z=& gt; Z.n ame==x.n ame)==I). ToList (); This method is to obtain the intersection, egg ache is look not to understand the function of the parameters, I ask you

CodePudding user response:

List1. RemoveAll (m=& gt; List2. The.findall (n=& gt; N.n ame==m.n ame)) this sentence don't know if you want as a result,

Linq and many more can't understand things, come on!

CodePudding user response:

 
//merge + to heavy
List1. Concat (list2). Distinct () ToList ();
//intersection
List1. Intersects (list2). ToList ();
//difference set, remove list1 with list2 element in the
List1. Except (list2). ToList ();

CodePudding user response:

Var list=list1. Where ((x, I)=& gt; List2. FindIndex (z=& gt; Z.n ame==x.n ame)==I). ToList ();
X is the element of list1
I is an element of subscript
If of the same element with list2 list1 subscript, this code should be unable to get to the intersection

CodePudding user response:

You move the mouse, I will know that

CodePudding user response:

reference 1st floor Denuin response:
list1. RemoveAll (m=& gt; List2. The.findall (n=& gt; N.n ame==m.n ame)) this sentence don't know if you want as a result,

Linq and many more can't understand things, come on!



An error of

CodePudding user response:

refer to the second floor bloodish response:
 
//merge + to heavy
List1. Concat (list2). Distinct () ToList ();
//intersection
List1. Intersects (list2). ToList ();
//difference set, remove list1 with list2 element in the
List1. Except (list2). ToList ();


Different data source, such removal should be according to the hashcode comparison, you should not my results

CodePudding user response:



The picture is no problem

CodePudding user response:

First of all, list2. FindIndex () returns the list2 subscript, should start from zero:
List1. RemoveAll (m=& gt; List2. FindIndex (n=& gt; N.n ame==m.n ame) & gt; - 1);
According to the truth like this do not have what problem, at least in my computer is running right, need to look at the actual content of the two list, may be there is something wrong with the data,

  •  Tags:  
  • C#