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

  • Home
  • SEARCH
  • 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 3485248
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:53:06+00:00 2026-05-18T10:53:06+00:00

I created an object called Participant. Now I want to have an array of

  • 0

I created an object called Participant.
Now I want to have an array of my Participant objects so that I could show them in a datagrid.

Here are the codes I tried (for better understanding of the problem, I removed the loops and datagrid codes):

Participant[] list = new Participant[count];
Participant one = new Participant(name, address);
Participant two = new Participant(name2, address2);

list[0] = one;
list[1] = two;

However, when I get values of one participant like through a messagebox in this manner,

MessageBox.Show(list[0].getName());

all it reflects are the data of participant two. Same is true if I have 3 objects, all it reflects is the data last sent into the array.

I know it is possible to have array of objects so there must be something I’m doing wrong. Or is there a better way to do this?

  • 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-18T10:53:06+00:00Added an answer on May 18, 2026 at 10:53 am

    With the code as presented, the only way I can think of causing that is if the backig field (in Participant) was declared “static“. If so, remove the “static“.

    Otherwise; does the actual code do a “new” for the two objects? Or does it overwrite an object after adding it to the array? (which means you have the same object twice in the array).

    I would expect ReferenceEquals(list[0], list[1]) to be false in a sane world – can you test this and let us know?

    Final thought; is there a “foreach” in the real code? It could be the infamous captured variable problem…

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

Sidebar

Related Questions

I have an object created in a host application and can access it remotely
I have tree control object created using CTreeCtrl MFC class. The tree control needs
I have created a json object from ruby with cobravsmongoose, however the attributes have
I've created a custom object, I have it appearing automatically on the Account details
Does a new SessionFactor y and Session object have to be created for each
I'm currently turning an array of pixel values (originally created with a java.awt.image.PixelGrabber object)
I've created an object called loginInterface in flex builder. When this object is initialized
I have an object, lets call it UnSerializableObject, that I can't and change that
I'm using Hibernate/JPA and have an @Entity object called Order, pointing at a MySQL
Once a controller object is created when does it become available for garbage collection?

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.