Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.67/5 (3 votes)
See more:
Hi friends i have a integer array and i have some values in it and my question is how to find difference in array values and store it in seperate array.

Example:

my array has 10,20,30,50,60 values
and ar1 must have 10,20,30
arr2 have 50,60 because difference of first three are same.
Posted
Updated 5-Mar-11 7:57am
v2
Comments
fjdiewornncalwe 5-Mar-11 12:14pm    
Please make an attempt to do your homework yourself first, then if you run into problems you can get great help here. You'll be a much better developer in the future if you learn to analyze your problems first.

1 solution

Can you use Linq?

C#
int[] Arr1 = { 10, 20, 30, 50, 60 };
int[] Arr2 = { 10, 20, 30 };
int[] Arr3 = Arr1.Except(Arr2).ToArray();
 
Share this answer
 
Comments
Albin Abel 5-Mar-11 10:03am    
Simple and correct. My 5. Proposed as answer
Manas Bhardwaj 5-Mar-11 10:15am    
sweet :) +5
fjdiewornncalwe 5-Mar-11 12:13pm    
It is a very good solution, but if questions look like homework like this one does, we discourage providing the code to the OP unless they provide us some indication that they have attempted something. We usually encourage them to show us what they have tried and where they encounter problems. +5 for a very concise and accurate answer!
Sergey Alexandrovich Kryukov 5-Mar-11 20:15pm    
Totally agree. I observe how in some Inquirers the seduction of easy answers blocks any chances to learn anything. I deny to answer is some apparent cases, explain why.
--SA
Sergey Alexandrovich Kryukov 5-Mar-11 20:15pm    
My 5 - for for the elegance of the Answer.
--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