我目前正在使用列表中包含的对象类型中的“CompareTo”方法对 C# 列表进行排序。我想按 WBS(工作分解结构)对所有项目进行升序排序,我可以使用以下代码很好地管理它:
public int CompareTo(DisplayItemsEntity other)
{
string[] instanceWbsArray = this.WBS.Split('.');
string[] otherWbsArray = other.WBS.Split('.');
int result = 0;
for (int i = 0; i < maxLenght; i++)
{
if (instanceWbsArray[i].Equals(otherWbsArray[i]))
{
continue;
}
else
{
result = Int32.Parse(instanceWbsArray[i]).CompareTo(Int32.Parse(otherWbsArray[i]));
break;
}
}
return result;
}
现在,我希望能够考虑多个参数(如项目名称中的字母顺序),然后再考虑第二个参数,即 WBS。我怎样才能做到这一点?