我如何...加入阵列元素? [英] How do I...joining array elemrnts?

查看:70
本文介绍了我如何...加入阵列元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好





我有阵列像



Hi All


I am having array like

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

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.

推荐答案

你不能真的这样做,因为你每行有两个字符串并且你可以;除非你连接它们,否则不要把两个字符串放到一个字符串中。

你想要做的更接近这个:

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:
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];
    }


你的第二个代码片段毫无意义,但我想你想要将字符串对连接到新数组中。所以它就像是:

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:
anotherarray[0]=(str[0] + str[1]);
// etc



OriginalGriff有答案。


OriginalGriff has the answer.


如果要针对一个数组元素存储多个项目,请使用多维数组 - 多维数组 [ ^ ]
Use multi-dimensional arrays if you want to store multiple items against one array element - Multidimensional Arrays[^]


这篇关于我如何...加入阵列元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆