日期:2014-05-18  浏览次数:20965 次

C# ArrayList 求解
我想在ArrayList中存入二维数组的坐标,然后取出来,可是句子不会写。有没有帮忙写一下,感激不尽

------解决方案--------------------
arraylist已经过时,你可以使用List<Point>或者List<PointF>
代码如下:
List<Point> list = new List<Point>()
{
new Point() { X = 1, Y = 1 },
new Point() { X = 2, Y = 2 },
...
};
list.Add(new Point(100, 100));
list.Add(new Point(101, 101));
...
foreach (Point p in list)
{
Console.WriteLine("x = {0}, y = {1}.", p.X, p.Y);
}
------解决方案--------------------
ArrayList不要用了,装箱拆箱的,用List吧
Point p = new Point();
p.X = 1;
p.Y = 2;

List<Point> list = new List<Point>();
list.Add(p);


foreach (Point pp in list)
{
Console.WriteLine(pp.X.ToString());
}
------解决方案--------------------
ArrayList a = new ArrayList();
string[,] arr = new string[10, 10];
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
arr[i, j] = Convert.ToString(i + j);
}
}
a.Add(arr);//存
string[,] b = a[0] as string[,];//取