c# - Issue with dictionary items -
c# - Issue with dictionary items -
i running issue , not sure going on, can help!
i gathering entries database , placing them in list collection, using list collection populate dictionary of "active" things, using list template , "active" entry items manipulated until "active" thing removed , new instance of "active" thing inserted dictionary list collection. issue seeing items in list collection beingness updated dictionary items.
this problem me @ at least. doing horribly wrong can provide improve solution.
for example:
public class dataentry { public string dataone { get; set; } public int datatwo { get; set; } } public static list<dataentry> datacollection = new list<dataentry>(); public static dictionary<int, dataentry> activelist = new dictionary<int, dataentry>(); private static int activeindex = 0; public static void loadlistfromdb() { datacollection.add(new dataentry() { dataone = "lakedoo", datatwo = 25 }); foreach (dataentry de in datacollection) { activelist.add(activeindex++, de); } (int = 0; < 5; i++) { activelist[0].datatwo -= 2; } if (activelist[0].datatwo < 25) { activelist.remove(0); } foreach (dataentry de in datacollection) { activelist.add(activeindex++, de); } }
both activelist
, datacollection
pointing same dataentry
instances.
you have create copy
of dataentry before inserting activelist
. see writing re-create constructor.
then do:
foreach (dataentry de in datacollection) { activelist.add(activeindex++, new dataentry(de)); }
c#
Comments
Post a Comment