在.NET/C#2.0中合并两个字符串数组?
可能重复:在.NET/C#2.0中合并两个字符串数组?,c#,.net,arrays,string,c#-2.0,C#,.net,Arrays,String,C# 2.0,可能重复: 如何合并两个string[]变量 例如: string[] x = new string[] { "apple", "soup", "wizard" }; string[] y = new string[] { Q.displayName, Q.ID.toString(), "no more cheese" }; 我想添加这两个,因此x的内容是:{“苹果”,“汤”,“向导”,Q.displayName,Q.ID.toString(),“不再有奶酪”}。这可能吗?如果结果必须进入
如何合并两个
string[]
变量
例如:
string[] x = new string[] { "apple", "soup", "wizard" };
string[] y = new string[] { Q.displayName, Q.ID.toString(), "no more cheese" };
我想添加这两个,因此x
的内容是:{“苹果”,“汤”,“向导”,Q.displayName,Q.ID.toString(),“不再有奶酪”}按那个顺序编码>。这可能吗?如果结果必须进入一个新的字符串数组,这很好;我只是想知道如何做到这一点。来自:
发件人:
由于您提到.NET 2.0,而LINQ不可用,您真的陷入了“手动”状态:
string[]newArray=新字符串[x.Length+y.Length];
对于(int i=0;i,由于您提到.NET 2.0,而LINQ不可用,所以您实际上被困在“手动”中:
string[]newArray=新字符串[x.Length+y.Length];
对于(int i=0;i您可以尝试:
string[] a = new string[] { "A"};
string[] b = new string[] { "B"};
string[] concat = new string[a.Length + b.Length];
a.CopyTo(concat, 0);
b.CopyTo(concat, a.Length);
然后,concat
是连接的数组。您可以尝试:
string[] a = new string[] { "A"};
string[] b = new string[] { "B"};
string[] concat = new string[a.Length + b.Length];
a.CopyTo(concat, 0);
b.CopyTo(concat, a.Length);
然后,concat
是连接的数组。试试这个
string[] front = { "foo", "test","hello" , "world" };
string[] back = { "apple", "soup", "wizard", "etc" };
string[] combined = new string[front.Length + back.Length];
Array.Copy(front, combined, front.Length);
Array.Copy(back, 0, combined, front.Length, back.Length);
试试这个
string[] front = { "foo", "test","hello" , "world" };
string[] back = { "apple", "soup", "wizard", "etc" };
string[] combined = new string[front.Length + back.Length];
Array.Copy(front, combined, front.Length);
Array.Copy(back, 0, combined, front.Length, back.Length);
对不起,哥们,这是2.0,不是。康卡特。对不起,哥们,这是2.0,不是。康卡特