排序字符串数组在C# [英] Sorting string array in C#

查看:154
本文介绍了排序字符串数组在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许这听起来不可思议,但时间长了编程之后,刚刚在数组排序。一切都如我所料,直到我试图梳理里面含有两个相同字符串的字符串数组。
让我们来看看:

Maybe it sounds weird, but after a long time programming, just got on array sorting. Everything was as I expected, until I tried to sort an array of strings containing two identical strings inside. Let's see:

假设具有以下内容:

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

Array.Sort(testArray, StringComparer.InvariantCulture); 

我得到在这种情况下是空值的数组平原。我认为这种行为是因为内部数组中的值都没有明显的值。对此有一个更好的解释?如何将非不同数组进行排序?

What I get in this situation is an array plain of null values. I got that this behavior is because the values inside array are not distinct values. Is there a better explanation for this? How to sort a non distinct array?

谢谢!

推荐答案

这code段工作正常

This code snippet is working properly

这篇关于排序字符串数组在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆