Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在c.net中通过2对反转字符串_C#_.net_Reverse - Fatal编程技术网

C# 在c.net中通过2对反转字符串

C# 在c.net中通过2对反转字符串,c#,.net,reverse,C#,.net,Reverse,例如,2对反转意味着:我们需要以返回ehllworodl的方式输出一个字符串helloworld。我们可以看到,每一对都会反转并连接起来输出。试试这个 string input = "helloworld"; string output = ""; for (int i = 0; i < input.Length - 1; i += 2) { output +=

例如,2对反转意味着:我们需要以返回ehllworodl的方式输出一个字符串helloworld。我们可以看到,每一对都会反转并连接起来输出。

试试这个

            string input = "helloworld";
            string output = "";
            for (int i = 0; i < input.Length - 1; i += 2)
            {
                output += input[i + 1];
                output += input[i];
            }

这仅在角色数为偶数时有效。如果您的字符串恰好是helloworl,则l将被忽略。@Vahlkron它肯定会起作用。由于条件i