0

我总是在以下行中收到此错误消息:

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]))
4

1 回答 1

3

SortedList文档指出您不能两次添加相同的键。

ArgumentException - 具有指定键的元素已存在于 SortedList 对象中。

于 2013-04-26T12:38:58.613 回答