다음 IComparer를 작성했지만 도움이 필요합니다. 번호 목록을 정렬하려고하지만 숫자 중 일부가 채워지지 않았을 수 있습니다.이 번호를 항상 목록의 끝에 보내야합니다 .. 예를 들어 ...정수에 대한 IComparer 및 빈 문자열의 끝을 강제로
[ EMPTY] 1 [EMPTY, 3, 2
는 ... [EMPTY]
] EMPTY
1, 2, 3,해질 것이며이 될 것이다 반전 ...
3, 2, 1, [EMPTY]
아이디어가 있으십니까?
public int Compare(ListViewItem x, ListViewItem y)
{
int comparison = int.MinValue;
ListViewItem.ListViewSubItem itemOne = x.SubItems[subItemIndex];
ListViewItem.ListViewSubItem itemTwo = y.SubItems[subItemIndex];
if (!string.IsNullOrEmpty(itemOne.Text) && !string.IsNullOrEmpty(itemTwo.Text))
{
uint itemOneComparison = uint.Parse(itemOne.Text);
uint itemTwoComparison = uint.Parse(itemTwo.Text);
comparison = itemOneComparison.CompareTo(itemTwoComparison);
}
else
{
// ALWAYS SEND TO BOTTOM/END OF LIST.
}
// Calculate correct return value based on object comparison.
if (OrderOfSort == SortOrder.Descending)
{
// Descending sort is selected, return negative result of compare operation.
comparison = (-comparison);
}
else if (OrderOfSort == SortOrder.None)
{
// Return '0' to indicate they are equal.
comparison = 0;
}
return comparison;
}
건배.
완벽하게 작동합니다. 감사! – paulio
그가 빈보다 숫자가 많으면 성능이 저하되지 않습니까? – Amsakanna
@Veer : 어떤 점에서? –