Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3210658
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:35:58+00:00 2026-05-17T14:35:58+00:00

I made a List to hold object in it, and then i’ll read it.

  • 0

I made a List to hold object in it, and then i’ll read it. But even if i give an index to List, i always get the same object results. Here is the 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.
                    for (int i = 0; i < treeDIds.Count; i++)
                    {
                        if (tempIds.TreeParentId == treeDIds[i].TreeDId)
                        {
                            treeDTempColl.Add(treeD);
                            break;
                        }
                    }
                }

            }

For example:

For the first loop TreeDId = 3 and TreeParentId = 1 then i insert them index 0. second loop TreeDId = 2, TreeParentId = 1, then insert them index 1. When loop into the List, i always get TreeDId = 2 and TreeParentId = 1, because the last loop is the second loop. What else i can do?

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T14:35:58+00:00Added an answer on May 17, 2026 at 2:35 pm

    There is only 1 tempIds object. the item in the list is the same one, and has the last item in it.
    move the TempIds tempIds = new TempIds(); into the loop

            foreach (ItemGroupTreeD treeD in itemTreeDColl)
            {
              TempIds tempIds = new TempIds();
    

    Remember that a list doesn’t contain copies of the data you add. It contains a reference to the object you’ve added. Doing it this way create a new object for you to insert every time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made list view with checkboxes. I have read similar articles n many
Hi I have made checked List Box in WPF but the binding is not
i made a program that uses a pre-made text file that hold a list
I made a custom TObjectList descendant designed to hold subclasses of a base object
I made a list and using the ul tag added an id, but the
I made a list from a CSV file. It looks like this: ['18', '29',
I've made a list who's content is loaded via AJAX, and it works as
I have made a list with few elements in it. Now everything looks right,
I have made a list view containing two childs. Now i am trying to
The html of this script is made with list items http://www.jeremymartin.name/projects.php?project=kwicks Where can I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.