-2
所以這裏是協議:我從我的同事那裏得到了一個代碼,他無法弄清楚他犯的錯誤。他想先按Y排序數組,然後按X(如果Y = Y)排序。你能幫我嗎?排序數組中的二維點...我錯過了什麼?
using System;
using System.Collections;
public class Point {
public int x;
public int y;
public Point(int x, int y) {
x = x;
y = y;
}
public string ToString() {
return x + "," + y;
}
}
public class PointList {
public static void Main(string [] args) {
ArrayList AL = new ArrayList();
Random R = new Random();
for (int i = 0; i < 10; i++) {
Point p = new Point(R.Next(50), R.Next(50));
AL.Add(p);
}
PrintValues(AL);
AL.Sort();
PrintValues(AL);
}
public static void PrintValues(IEnumerable myList) {
foreach (Object obj in myList)
Console.WriteLine("{0}", obj);
Console.WriteLine();
}
}
任何想法?