Click here to Skip to main content
15,909,835 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Hi please help me to add the two array

Build arrays A & B,
like Array A={1,2,3,4}
and Array B={5,6,3,2}
add these two array in Array C
and sort the array display elements in descending order.
Please Help me to how can i do that.

Regards
Basheer
Posted
Updated 11-Apr-11 22:27pm
v2
Comments
Pong D. Panda 12-Apr-11 2:20am    
You need to further elaborate your question. Give us a sample answer on your given A and B inputs
Sandeep Mewara 12-Apr-11 8:35am    
No effort.
BobJanova 12-Apr-11 8:46am    
Did you just copy the question off your homework and post it here without even reading it? Come on, use a bit of effort.

1 solution

There are two ways to do this: One way includes the duplicates in the result, the other doesn't.
Easy way:
int[] A = new int[] { 1, 2, 3, 4 };
int[] B = new int[] { 5, 6, 3, 2 };
List<int> combined = new List<int>();
combined.AddRange(A);
combined.AddRange(B);
combined.Sort();
int[] C = combined.ToArray();</int></int>

Harder way:
int[] A = new int[] { 1, 2, 3, 4 };
int[] B = new int[] { 5, 6, 3, 2 };
List<int> combined = new List<int>();
combined.AddRange(A);
foreach (int i in B)
    {
    if (!combined.Contains(i))
        {
        combined.Add(i);
        }
    }
combined.Sort();
int[] C = combined.ToArray();</int></int>
 
Share this answer
 
Comments
Basheer Belgod 13-Apr-11 0:33am    
I got it
Thank you so much

From
Basheer

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