Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/300.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#_Arrays - Fatal编程技术网

C# 反转简单字符串数组

C# 反转简单字符串数组,c#,arrays,C#,Arrays,我试图反转数组中的字符串元素,但得到的是精确的字符串顺序。这是密码 public static void ReverseArrayElements() { Console.WriteLine("This will init array elements and reverse its elements"); string[] elements = { "one, two, three" }; for (int

我试图反转数组中的字符串元素,但得到的是精确的字符串顺序。这是密码

public static void ReverseArrayElements()
        {
            Console.WriteLine("This will init array elements and reverse its elements");
            string[] elements = { "one, two, three" };
            for (int i = 0; i < elements.Length; i++)
            {
                Console.WriteLine("Array elements before reversing: {0}", elements[i]);    
            }
            Console.WriteLine("\n");

            Array.Reverse(elements);

            for (int i = 0; i < elements.Length; i++)
            {
                Console.WriteLine("Array elements after reversing: {0}", elements[i]);    
            }
            Console.ReadLine();
        }
结果是一,二,三,再排序一,二,三


我在这里做错了什么?

您已经创建了一个由一个元素组成的数组,其中包含字符串1、2、3

相反,您希望通过以下方式初始化该阵列:

        string[] elements = { "one", "two", "three" };

您已经创建了一个由一个元素组成的数组,其中包含字符串1、2、3

相反,您希望通过以下方式初始化该阵列:

        string[] elements = { "one", "two", "three" };

你可以使用数组。反转你的数组。

你可以使用数组。反转你的数组