I’ve created a hashtable of two-dimensional arrays in c# and cannot figure out how to directly access the array values, the following is my current code:
// create the hashtable Hashtable hashLocOne = new Hashtable(); // add to the hashtable if we don't yet have this location if (!hashLocOne.ContainsKey(strCurrentLocationId)) hashLocOne.Add(strCurrentLocationId,new double[20, 2] { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } }); // add to the value at a given array position, this does not work hashLocAll[strReportLocationId][iPNLLine, 0] += pnl_value;
The Hashtable doesn’t know what kind of objects are stored in it; you have to manually cast each one:
You should use a Dictionary instead of a Hashtable if possible: