比较两本词典的最佳方法是什么?其中的项目“应该”始终处于相同的顺序。
dictionary<string, int> _requiredItems = new dictionary<string, int>();
dictionary<string, int> _collectedItems = new dictionary<string, int>();
_requiredItems.Add("Cube", 2); //2 being the number of Cubes required
_collectedItems.Add("Cube", 0); //0 meaning we don't have any collected
_requiredItems.Add("Sphere", 3); //3 being the number of Spheres required
_collectedItems.Add("Sphere", 0); //0 meaning we don't have any collected
//stuff happens here
int _itemCollected = _itemsCollected["Cube"];
_itemsCollected["Cube"] = _itemCollected++;
所以现在有一种比较它们的方法。如果 _collectedItems 值 = _requiredItems 值,则返回 true,如果不是 false。