c# - adding object to a dictionary get a different value than expected -


i have strange behavior, working on 5 days , cant seems find problem yet. don't know whether it's stupid mistakes or i'm using bad approach such things happened. assumed list problem i'm not sure.

i'm using list of class named item models of json. think there's no problem on list of item, because have checked of item on list, , has same value on json.

my approach using list accessed key on every item, i'm using dictionary. but strange goes this:

item added dictionary goes looped (adding same key , value) after item number 30, when checked using breakpoints, var item in items has right value expected. when added dictionary, item added it(dictionary) not item in local variable foreach statement added before

this model json

class item {     public string key { get; set; }     public string description { get; set; }     public string question { get; set; }     public double cf { get; set; } } 

here code has strange behavior cant seemed find out:

modelitems = new dictionary<string, factitem>(); itemsdictionary = new dictionary<string, item>();  foreach (item item in items)             {                 item.cf = 0;                 if (!item.question.equals(""))                 {                     factitem f = new factitem(item.key, item.description, item.question);                     f.cf = 0;                     modelitems.add(item.key, f);                 }                 itemsdictionary.add(item.key, item);             } 

the factitem inherit item class, , has same problem too.

here screenshot. i'm using breakpoint , iterate right before strange behavior happened , when strange behavior begin:

sorry, dont have enough reputation uploaded picture


i using different approach translating list dictionary, using dictionary<tkey,tvalue> = list.todictionary(funcforkey, funcforvalue) still facing same problem.

i appreciate responded question

if order of entries important, should consider using sorteddictionary object instead of generic dictionary; more details on implementation @ msdn online: https://msdn.microsoft.com/en-us/library/f7fta44c%28v=vs.110%29.aspx hope may help. best regards,


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -