在 C# 中将 2 个本地字符串 [] 添加到单个数组中

Add 2 local string[] into a single array in C#

我们正在从 2 台客户端计算机接收两个字符串到我们的第 3 台服务器计算机。该数组目前是一维的。我们需要将 resultanswer 数组的每个成员相加并输出第三个数组。但是我们将它们用作局部变量string[].

我们如何将 answerresult 的值添加到一个数组中。 例如:

answer[0]+result[0]= final[0]

..........

answer[76]+result[76]=final[76]

更新了代码

    namespace ExampleLib.Server
{

    public class Server
    {
        string[] answer = new string[77];
        string[] result = new string[77];


    private void ClientReceiveData(object sender, ConnectedClient.NetDataEventArgs e)
    {
        if (string.IsNullOrEmpty(e.Message) == false)
        {
        if (e.ID == 0)
                {
                    answer = e.Message.Split(',');
                }

                if (e.ID==1)
                {
                    result = e.Message.Split(',');                    
                }
                var final = answer.Zip(result, (x, y) => x + y).ToArray();

                Trace.WriteLine(String.Join(Environment.NewLine, final));

            }
        }
    }

更新 1(使用 Zip 方法):

尝试使用Zip方法,像这样:

var final = answer.Zip(result, (x, y) => x + y).ToArray();