첫 번째 문자를 넘어 가고 싶은 경우에, 나는 비교 자 구현해야합니다 :
class MyComparer : IComparer<string>
{
public int Compare(string x, string y)
{
if ((x == null) && (y == null))
{
return 0;
}
if (x == null)
{
return 1;
}
if (y == null)
{
return -1;
}
var l = Math.Min(x.Length, y.Length);
for (var i = 0; i < l; i++)
{
var c = x[i];
var d = y[i];
if (c != d)
{
if (char.ToLowerInvariant(c) == char.ToLowerInvariant(d))
{
return StringComparer.Ordinal.Compare(new string(c, 1), new string(d, 1));
}
else
{
return StringComparer.OrdinalIgnoreCase.Compare(new string(c, 1), new string(d, 1));
}
}
}
return x.Length == y.Length ? 0 : x.Length > y.Length ? 1 : -1;
}
}
을 그리고 그것을 사용
var myComparer = new MyComparer();
source.OrderBy(s => s, myComparer);
으로 좋을 수 있습니다'소스를 .OrderBy (s => char.ToLower (s [0])). 다음으로 축소 (s => s)'. 그 일을하는 것 같습니다. 어쨌든 +1하십시오. –
+1하지만 스트링의 중간에 마개가없는 경우에만 작동합니까? (부여 된, OP의 예에는 어떤 것도 없지만 명시된 요구 사항이이 가능성을 배제하지는 않습니다). – Baldrick
@ Baldrick 예, 위/아래 규칙은 첫 번째 문자에만 적용된다고 가정했습니다. – MarcinJuraszek