c# - 反转简单字符串数组

标签 c# arrays

我正在尝试反转数组中的字符串元素,但我得到的是准确的字符串顺序。这是代码

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();
        }

结果为一、二、三,再次排序后为一、二、三。

我在这里做错了什么?

最佳答案

您已经创建了一个只有一个元素的数组,其中包含字符串“一、二、三”。

相反,您想使用以下方法初始化该数组:

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

关于c# - 反转简单字符串数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13320757/

相关文章:

c# - 为什么使用命令行构建 VS 安装项目时没有输出?

c# - 获取特定的xelement子值

mysql - 如何从 json 数组列中获取具有特定键值的 json 对象?

c - 带有结构体数组的 Malloc

java - 带有 boolean 数组的 SharedPreference 上的 ArrayIndexOutOfBoundsException?

ios - addObjectsFromArray 不会将它们添加为新对象

c# - 如何在 Windows 中嵌入 tabtip.exe

c# - 为 datagridview 单元格赋值

c# - 使用 EWS 托管 API 将电子邮件保存到 .MSG 文件

php - 在有序数组中添加额外的数字