我有这段代码的问题C#结构化列表
我有这样的结构
public struct bounds
{
public int xmax = 0;
public int xmin = 0;
public int ymax = 0;
public int ymin = 0;
};
和我做一个清单出来的
List<bounds> map = new List<bounds>();
我试图存储二维数组中的空间(或对象)的边界(其xmax,xmin,ymin,ymax)我有这个整数y变量,当它到达这个代码时它会变成一些数字,但我不断收到红线UND呃我的列表相关的代码“地图”(i和j是通过二维数组去专柜)
if(!(map.Contains(y))) //if the list doesn't already have this number
{
map.Add(y);
map[y].xmax = i; //and set its xmax, xmin, ymax, ymin
map[y].xmin = i;
map[y].ymax = j;
map[y].ymin = j;
}
if(map[y].xmax < j) // if its already in the list look at the current
map[y].xmax = j; // boundaries and decide if new ones should be set
if(map[y].xmin > j)
map[y].xmin = j;
if (map[y].ymax < j)
map[y].ymax = i;
if(map[y].ymin > j)
map[y].ymin = i;
见[为什么可变结构是邪恶的](http://stackoverflow.com/questions/441309/why-are-mutable-structs-vil) –
为什么不使用'System.Drawing.Rectangle'? – ja72