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


I am having array like

C#
string [] str  its out put is 

str[0]='USD'
str[1]='60.1'
str[2]='INR'
str[3]='0.165'

and so on


now i want to take this array in to another array the output must look like this

C#
string [] anotherarray

anotherarray[0]=(str[0]='USD',str[1]='60.1')
anotherarray[1]=(str[2]='INR',str[3]='0.165')


how to achive it please give hint.
Posted
Updated 18-Aug-14 21:33pm
v2

You can't really do that, as you have two strings per row and you can;'t put two strings into a single string unless you concatenate them.
Probably what you want to do is closer to this:
C#
string[] str = new string[4];
str[0] = "USD";
str[1] = "60.1";
str[2] = "INR";
str[3] = "0.165";
string[][] anotherarray = new string[str.Length / 2][];
for (int i = 0, x = 0; i < str.Length && x < anotherarray.Length; i += 2, x++)
    {
    anotherarray[x] = new string[2];
    anotherarray[x][0] = str[i + 0];
    anotherarray[x][1] = str[i + 1];
    }
 
Share this answer
 
Comments
Richard MacCutchan 19-Aug-14 4:46am    
That makes sense.
murkalkiran 19-Aug-14 4:52am    
Thanku Very Much Bro Its Worked For me,
OriginalGriff 19-Aug-14 5:08am    
You're welcome!
Your second code snippet makes no sense, but I assume you want to concatenate the pairs of strings into the new array. So it would just be something like:
C#
anotherarray[0]=(str[0] + str[1]);
// etc

OriginalGriff has the answer.
 
Share this answer
 
v4
Use multi-dimensional arrays if you want to store multiple items against one array element - Multidimensional Arrays[^]
 
Share this answer
 

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