c#,字符串比较

            string value_str = string.Empty;
            int n = 10;
            string[] strs = new string[n];
            Console.WriteLine($"输入{n}个任意字符串");
            for (int i = 0; i < n; i++)
            {
                strs[i] = Console.ReadLine();
            }
            //冒泡排序,依次比较相邻的两位
            for (int i = 0; i < n - 1; i++)
            {
                for (int j = 0; j < n - 1 - i; j++)
                {
                    if (string.Compare(strs[j], strs[j + 1]) > 0)
                    {
                        value_str = strs[j];
                        strs[j] = strs[j + 1];
                        strs[j + 1] = value_str;
                    }
                }


            }
            Console.WriteLine("排序后为:");
            foreach (var item in strs)
            {
                Console.WriteLine(item);
            }
            Console.ReadKey();
原文地址:https://www.cnblogs.com/singhwong/p/11918448.html