I have a dictionary that will be populated from the results of a query. Due to this, I do not know what data values will be going into the dictionary when I initialize it (though obviously I do know what data types will be used). I'm new to C# - how can I set this up?
In pseudocode, the dictionary structure I want is:
{ "visa": [2.75, 3.33], "mastercard": [1.00, 4.32], ... } This is what I have so far, but its not compiling:
//initialize the dictionary but do not populate yet Dictionary<string, List<decimal>> cardtype_total_amount; //simulate getting the first card type from the db string cardtype = "visa"; //initialize the "visa" key if (!cardtype_total_amount.ContainsKey(cardtype)) cardtype_total_amount.Add(cardtype, new List<decimal>(){0, 0}); //simulate updating the values for "visa" from the db (this would happen lots of times for each card type): cardtype_total_amount[cardtype][0] += 0.5; cardtype_total_amount[cardtype][1] += 1.7; //add more keys for other cardtypes, and update their totals as per above...