List<T>().Add problem C# -


i made list hold object in it, , i'll read it. if give index list, same object results. here code:

            list<tempids> treedids = new list<tempids>();             tempids tempids = new tempids();               foreach (itemgrouptreed treed in itemtreedcoll)             {                  //idleri listeye alıyoruz daha sonra karşılaştırma yapmak için                 tempids.treedid = treed.id;                 tempids.treeparentid = treed.treeparentid;                 treedids.insert(treedids.count, tempids);                 //----                  //eğer ilk gelen detay id ile methoda gelen id bir ise collectiona ekliyoruz.                 if (tempids.treedid == grouptreedid)                 {                     treedtempcoll.add(treed);                 }                 else                 {                     //burada karşılaştırma yapıyoruz.                     (int = 0; < treedids.count; i++)                     {                         if (tempids.treeparentid == treedids[i].treedid)                         {                             treedtempcoll.add(treed);                             break;                         }                     }                 }              } 

for example:

for first loop treedid = 3 , treeparentid = 1 insert them index 0. second loop treedid = 2, treeparentid = 1, insert them index 1. when loop list, treedid = 2 , treeparentid = 1, because last loop second loop. else can do?

thank you.

there 1 tempids object. item in list same one, , has last item in it. move tempids tempids = new tempids(); loop

        foreach (itemgrouptreed treed in itemtreedcoll)         {           tempids tempids = new tempids(); 

remember list doesn't contain copies of data add. contains reference object you've added. doing way create new object insert every time.


Comments

Popular posts from this blog