Say result1 and result2. I am using the code as follow which will exclude all the items that are in result2 from result1.
But it's talking too much time, since I have thousands of item on both list of int array. Is there any other approach with which I can achieve same efficiently? Appreciated!!
List result1 = new List { new int[] { 1, 2, 3 }, new int[] { 4, 5, 6 } };
List result2 = new List { new int[] { 1, 2, 3 }, new int[] { 7, 8, 9 } };
result2.ForEach(t => result1.RemoveAll(z => z.OrderBy(k=>k).SequenceEqual(t.OrderBy(k=>k))));
VulpesPosted Dec 2, 2012, 3:12 PM
Deer ParkPosted Dec 2, 2012, 5:18 PM
List
I guess it's just because the size of the list is too large.
VulpesPosted Dec 2, 2012, 4:15 PM
You can then use the version of the code which doesn't sort the arrays in the Equals method.
My suspicion is that both the LINQ code and my version are sorting each array multiple times which will clearly slow things down. So just sorting the arrays the one time might help here.
Deer ParkPosted Dec 2, 2012, 4:08 PM
Deer ParkPosted Dec 2, 2012, 3:04 PM
At this point I am not sure what other options I have.
VulpesPosted Dec 2, 2012, 2:54 PM
If they can't, then using HashSets may be quicker.
Deer ParkPosted Dec 2, 2012, 2:49 PM
Yes, the order of the integer array is not relevant in my case. So like you said {1, 2, 3} would be regarded as equal to {1, 3, 2}.
Any Suggestions or tips?
VulpesPosted Dec 2, 2012, 2:44 PM
http://www.c-sharpcorner.com/Forums/Thread/193268/how-to-exclude-two-ilistint.aspx
or are you wanting two integers arrays to be regarded as equal if they contain the same elements, regardless of how they're ordered?
So {1, 2, 3} would be regarded as equal to {1, 3, 2}.