Mucosoft
Megapat
- Katılım
- 5 Mart 2014
- Mesajlar
- 5.514
- Makaleler
- 12
- Çözümler
- 41
Fonksiyon Kitaplığı
Nesne
Hata
KeyNotFoundException: The given key was not present in the dictionary.
Nasıl çözerim?
C#:
static Dictionary<string, int> Items = new Dictionary<string, int>();
static string[] ItemList = { "Iron" };
static string SelectedItem = "Iron";
void Start()
{
foreach (var Item in ItemList)
{
Items.Add(Item, 0);
}
}
public static void AddItem(string ItemName)
{
if (Items.ContainsKey(ItemName))
{
int Value = Items["ItemName"];
Items.Remove(ItemName);
Value++;
Items.Add(ItemName, Value);
}
}
public static int GetItemAmount(string ItemName)
{
return Items[ItemName];
}
C#:
void Start()
{
FactoryGameInventory.AddItem("Iron");
FactoryGameInventory.AddItem("Iron");
Debug.Log(FactoryGameInventory.GetItemAmount("Iron").ToString());
}
KeyNotFoundException: The given key was not present in the dictionary.
Nasıl çözerim?