[英]Difficulties with SortedList
I always get this error message in the following line: 我总是在以下行中收到此错误消息:
posDiffRectFList.Add(posDiff_Float, Backgrounds.levellistshapes[j]);
ArgumentException: An entry with the same key already exists. ArgumentException:具有相同键的条目已存在。
What is wrong? 怎么了? What should I change?
我应该改变什么?
For example: Is it possible to add this to a SortedList
? 例如:可以将其添加到
SortedList
吗? Or is that not possible because it is two times the same key(1.5f)? 还是因为两次输入相同的密钥(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]))
The SortedList documentation states that you cannot add the same key twice. SortedList文档指出您不能两次添加相同的密钥。
ArgumentException - An element with the specified key already exists in the SortedList object.
ArgumentException-具有指定键的元素已存在于SortedList对象中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.