我总是在以下行中收到此错误消息:
posDiffRectFList.Add(posDiff_Float, Backgrounds.levellistshapes[j]);ArgumentException:已存在具有相同键的条目。
怎么啦?我应该改变什么?
例如:可以将此内容添加到SortedList中吗?或者这是不可能的,因为它是相同密钥(1.5F)的两倍?
posDiffRectFList.Add(1.5f, (10,20,100,100));
posDiffRectFList.Add(1.5f, (50,70,60,60));
SortedList<float, System.Drawing.RectangleF> posDiffRectFList = new SortedList<float, System.Drawing.RectangleF>();
for (int j = 0; j <= Backgrounds.LevelListTiles.Count - 1; j++)
{
posDiff = new Vector2((int)((Backgrounds.LevelListTiles[j].X + Backgrounds.LevelListTiles[j].Width * 0.5) - (Basketball_Rect.X + Basketball_Rect.Width * 0.5)), (int)((Backgrounds.LevelListTiles[j].Y + Backgrounds.LevelListTiles[j].Height * 0.5) - (Basketball_Rect.Y + Basketball_Rect.Height * 0.5)));
posDiff_Float = posDiff.Length();
posDiffRectFList.Add(posDiff_Float, Backgrounds.LevelListTiles[j]);
}
//check for collision between tiles and basketball, beginning with the lowest posDiff_Float and his corresponding RectangleF
for (int j = 0; j <= posDiffRectFList.Count - 1; j++)
{
if (kugelNewRect.IntersectsWith(posDiffRectFList.Values[j]))发布于 2013-04-26 20:38:59
SortedList文档指出,您不能将同一密钥添加两次。
ArgumentException - SortedList对象中已存在具有指定键的元素。
https://stackoverflow.com/questions/16236613
复制相似问题