어떻게 지역별로 사각형 목록을 정렬합니까? MSDN 라이브러리에서에서 IComparable으로 찾고, 그러나 그것을 알아낼 수 없습니다 ... 나는이 쓴 :정렬 목록 <Rectangle>
SortedL= new List<Rectangle>();
int count1 = 0;
int count3 = redovi;
while (count1 < count3)
{
int count2 = 0;
while (count2 < count3)
{
int x = Oblici[count1].Width;
int y = Oblici[count1].Height;
int z = Oblici[count2].Width;
int w = Oblici[count2].Height;
int area1 = x * y;
int area2 = z * w;
int a = area1.CompareTo(area2);
if (a < 0)
{
count1 = count2;
if (count2 < (count3 - 1))
{
count2++;
}
else break;
}
else if (a == 0)
{
if (count2 < (count3 - 1))
{
count2++;
}
else break;
}
else if (a > 0)
{
if (count2 < count3 - 1)
{
count2++;
}
else break;
}
}
SortedL.Add(Oblici[count1]);
Oblici.RemoveAt(count1);
count3 = (count3 - 1);}}
을 그리고 ...
그것은 작동하지만, 꽤 추한, 나는 더 쉬운 방법이 알고 당신은 LINQ를 사용할 수 있습니다 가정
좋아! 람다는'비교'대리자를 만듭니다. –