473,385 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to merge two arrays as one

ad
I have two array like
string a1= {"dog","dock","deer"}
string a2= {"lion","tiger"}

How can I merge a1 and a2 to a3
a3: {"dog","dock","deer", "lion","tiger"}
Oct 5 '06 #1
2 61376

ad wrote:
I have two array like
string a1= {"dog","dock","deer"}
string a2= {"lion","tiger"}

How can I merge a1 and a2 to a3
a3: {"dog","dock","deer", "lion","tiger"}
Well, for starters I assume that the declarations are, more properly:

string[] a1 = { "dog", "dock", "deer" };
string[] a2 = { "lion", "tiger" };

then you can append them using:

string[] a3 = new string[a1.Length + a2.Length];
a1.CopyTo(a3, 0);
a2.CopyTo(a3, a1.Length);

Oct 5 '06 #2
>I have two array like
string a1= {"dog","dock","deer"}
string a2= {"lion","tiger"}

How can I merge a1 and a2 to a3
a3: {"dog","dock","deer", "lion","tiger"}
Create a new array long enough to contain all elements from both
arrays. Copy over the elements from the old arrays to the new (using
Array.Copy, Array.CopyTo or manually looping).
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Oct 5 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Tmenke | last post by:
Can someone help, I have two arrays and want to merge them into a third array.What I want to do is, after I create this third array (combination of the first two) is to erase the original two...
2
by: nickdu | last post by:
Is there a tool that will merge XML documents? We also need the reverse, we need to be able to create a Diff of two documents. What we're trying to do is just store differences of documents at...
1
by: psmahesh | last post by:
Hi folks, I am comparing two arrays and removing matches from the second array from the first array. Can someone take a look at this code below and mention if this is okay and perhaps if there...
13
by: ralphedge | last post by:
These sorts work fine on 100000 ints but if I go much higher they will both segmentation fault **************************MERGESORT********************* mergesort(int *a, int size) //a is...
15
by: hobosalesman | last post by:
Is there a function or library somewhere that merges 2 JSON data structures? For instance this: { "one": } plus { "one": } equals
5
by: John | last post by:
Hi Is there a way to merge two or more single dimension string arrays into a single, single dimension string array? Thanks Regards
1
by: chiefychf | last post by:
I'm working on a school project and I am having a few issues... The program calls for three arrays a,b,c that have to be sorted, then compared to even or odd and stored in arrays d & e, then merge...
7
by: mooon33358 | last post by:
I have a little problem with implementing a recursive merge sort I have to use a function mergesort that takes 3 arguments - an array, its size, and an help array(i.e mergesort(int array, int...
6
by: p4willi | last post by:
I've defined two arrays in a Module called PubVars Public Type LinesRec CORRECT As Integer QUESTION As String PROC As Integer PAY As Integer End Type Public Lines_Array() As...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.