Click here to Skip to main content
15,888,977 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,


I am having two arrays having data like

array1=1,2,3,4,5,6
array2=4,6
here i need to compare these two arrays and i need new array which are remain in array 1

array3=1,2,3,5


Thanks in Advance

Seshu
Posted

1 solution

Well here is one way of doing it -

C#
int[] arr1 = new int[] { 1, 2, 3, 4, 5, 6 };
int[] arr2 = new int[] { 4, 6 };
//Converting to list
List<int> list1 = new List<int>(arr1);
List<int> list2 = new List<int>(arr2);
//Using the Except extension method
IEnumerable<int> list3 = list1.Except<int>(list2);
//Converting back to array
int[] arr3 = list3.ToArray<int>();


Others might be having a better way of doing it.
Good luck.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 30-Jun-11 4:57am    
Using extension methods is a good, elegant way, my 5.
--SA
Tarun.K.S 30-Jun-11 5:10am    
Thanks a lot SA! :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900