1.txt,10.txt ,2.txt,3txt 排序
怎么c# 编写 把1.txt,10.txt ,2.txt,3txt 排序成为 1.txt,2.txt,3txt 10.txt
我是个初学者 请各位帮帮忙
------解决方案-------------------- public class NameSorter : IComparer
{
public int Compare(object x, object y)
{
if (x == null && y == null)
{
return 0;
}
if (x == null)
{
return -1;
}
if (y == null)
{
return 1;
}
FileInfo xInfo = new FileInfo(x.ToString());
FileInfo yInfo = new FileInfo(y.ToString());
if (xInfo.FullName.Length > yInfo.FullName.Length)
{
return 0;
}
return xInfo.FullName.CompareTo(yInfo.FullName);
}