To add a new item:
inv_stored[1] = new data_inv { demand = 4 };
To modify the existing item:
data_inv d = inv_stored[1];
d.demand = 5;
inv_stored[1] = d;
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi I have a struct and dictionary as below and I'm trying to add it as a custom value like
public struct data_inv
{
//protected static int p;
public float inventory;
public float supply;
public float demand;
};
public static IDictionary<int, data_inv> inv_stored = new Dictionary<int, data_inv>();
and I have tried to add value to dictionary but when I try to add a value like inv_stored[1].demand = 4; its gives System.Collections.Generic.KeyNotFoundException: 'The given key was not present in the dictionary.' exception. I'm new to coding, could any explain what im doing wron
To add a new item:
inv_stored[1] = new data_inv { demand = 4 };
To modify the existing item:
data_inv d = inv_stored[1];
d.demand = 5;
inv_stored[1] = d;