我对这段代码有问题
我有这个结构
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)中我在与我的列表“地图”关联的代码下不断出现红线(i 和 j 是用于遍历 2D 数组的计数器)
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;