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 7018249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:01:17+00:00 2026-05-27T23:01:17+00:00

I am not quite sure what exactly goes on when I run the code

  • 0

I am not quite sure what exactly goes on when I run the code below to add four values (a, b, c ,d ) into my hash table with C#. But I do know that I get wrong answer. after the loop finished, I get 4 ds stored in my hash table . Help me, Please!

Hashtable cirlTmp = new Hashtable();

CycleLink mycylink = new CycleLink();
int i = 0;
for (i = 0; i < 4; i++)
{
      mycylink.link_id = i;
      mycylink.begine_state = i;//
      mycylink.end_state = 1 + i;
      mycylink.proscDescrp = (process_descrp)i;
      lock (cirlTmp.SyncRoot)
      {
           cirlTmp.Add(i, mycylink);
      }   
 }

what I get in the cirlTemp is

  [3]: link_id=3 begine_state=3 end_state=4 proscDesrp=4;
  [2]: link_id=3 begine_state=3 end_state=4 proscDesrp=4;
  [1]: link_id=3 begine_state=3 end_state=4 proscDesrp=4;
  [0]: link_id=3 begine_state=3 end_state=4 proscDesrp=4;

……. Any hint will be helpful! thanks

  • 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-27T23:01:18+00:00Added an answer on May 27, 2026 at 11:01 pm

    move your CycleLink declaration inside the for loop, you just have a reference to the same object in 4 places in your Hashtable instead of 4 different object

    and the value of your object is just the value you set it to in the last run in your loop, that’s when i was 3

    Hashtable cirlTmp = new Hashtable();
    
    int i = 0;
    for (i = 0; i < 4; i++)
    {
      CycleLink mycylink = new CycleLink();
      mycylink.link_id = i;
      mycylink.begine_state = i;//
      mycylink.end_state = 1 + i;
      mycylink.proscDescrp = (process_descrp)i;
      lock (cirlTmp.SyncRoot)
      {
        cirlTmp.Add(i, mycylink);
      }   
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem that is common, but I am not quite sure exactly
I have been reading ASN.1 specification, but I am not quite sure what exactly
I'm not sure exactly how to phrase this, but here goes: I have a
I'm not quite sure if this is possible, or falls into the category of
I'm not quite sure how this happened, but somehow a completely empty hierarchy of
I'm not quite sure what this is called, but I've spent some time thinking
I have read other related posts, but am still not quite sure how, or
I'm not sure exactly what went wrong here, but ReSharper 4.5 RTM seems to
I'm not entirely sure how to post this question, but here goes... I have
I'm not quite sure exactly how Graphics work in Java so I having trouble

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.