例として、StringComparerとList<string>.Sortメソッドを使って、その結果の違いを見てみます。 List<string.Sortメソッドは並べ替え時の比較を行うためのIComparer<string>を引数にとるため、StringComparerを使用することが出来ます。
StringComparerを指定してListをソートする際の文字列比較順を指定する
using System;
using System.Collections.Generic;
class Sample {
static void Main()
{
var words = new List<string>() {"cant", "can't", "can not", "cannot"};
Console.WriteLine(String.Join(", ", words));
words.Sort(StringComparer.CurrentCulture); // CurrentCultureの比較順でソートする
Console.WriteLine(String.Join(", ", words));
words.Sort(StringComparer.Ordinal); // Ordinalの比較順でソートする
Console.WriteLine(String.Join(", ", words));
}
}
実行結果
cant, can't, can not, cannot can not, cannot, cant, can't can not, can't, cannot, cant
Listとソート順の定義については基本型のソートと昇順・降順でのソートを参照してください。