gpt4 book ai didi

c# - 在 C# 中对字符串数组进行排序

转载 作者:行者123 更新时间:2023-12-03 03:07:40 25 4
gpt4 key购买 nike

这个问题不太可能对任何 future 的访客有帮助;它只与一个小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,通常不适用于互联网的全局受众。如需帮助使这个问题更广泛适用,visit the help center .




8年前关闭。




也许这听起来很奇怪,但经过长时间的编程,我才开始学习数组排序。一切都如我所料,直到我尝试对包含两个相同字符串的字符串数组进行排序。让我们来看看:

假设有以下内容:

string[] testArray = new string[]
{
"aa",
"ab",
"ac",
"ad",
"ab",
"af"
};

Array.Sort(testArray, StringComparer.InvariantCulture);

在这种情况下,我得到一个空值数组。我知道这种行为是因为数组中的值不是不同的值。对此有更好的解释吗?如何对非不同数组进行排序?

最佳答案

此代码片段工作正常
enter image description here

关于c# - 在 C# 中对字符串数组进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6167068/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com