首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SortedList的困难

SortedList的困难
EN

Stack Overflow用户
提问于 2013-04-26 20:35:18
回答 1查看 397关注 0票数 0

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

代码语言:javascript
复制
posDiffRectFList.Add(posDiff_Float, Backgrounds.levellistshapes[j]);

ArgumentException:已存在具有相同键的条目。

怎么啦?我应该改变什么?

例如:可以将此内容添加到SortedList中吗?或者这是不可能的,因为它是相同密钥(1.5F)的两倍?

代码语言:javascript
复制
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]))
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-04-26 20:38:59

SortedList文档指出,您不能将同一密钥添加两次。

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

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16236613

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档