小编C P*_*ton的帖子

字典中的KeyNotFound异常(T)

我准备好把头撞在墙上

我有一个名为Map的类,它有一个名为tiles的字典.

class Map
{
    public Dictionary<Location, Tile> tiles = new Dictionary<Location, Tile>();
    public Size mapSize;

    public Map(Size size)
    {
        this.mapSize = size;
    }
   //etc...
Run Code Online (Sandbox Code Playgroud)

我暂时填写这本字典来测试一些东西..

public void FillTemp(Dictionary<int, Item> itemInfo)
    {
        Random r = new Random();
        for(int i =0; i < mapSize.Width; i++)
        {
            for(int j=0; j<mapSize.Height; j++)
            {
                Location temp = new Location(i, j, 0);

                int rint = r.Next(0, (itemInfo.Count - 1));

                Tile t = new Tile(new Item(rint, rint));

                tiles[temp] = t;
            }
        }

    }
Run Code Online (Sandbox Code Playgroud)

并在我的主程序代码中

Map m …
Run Code Online (Sandbox Code Playgroud)

c# dictionary equals keynotfoundexception

2
推荐指数
1
解决办法
425
查看次数

标签 统计

c# ×1

dictionary ×1

equals ×1

keynotfoundexception ×1