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 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 called ValueBox that I created like this: function ValueBox(params) {
I have created an object called Project that has different properties (strings and some
In my .NET 3.5 project, I have created an OracleConnection object called conn. Then
I have a service that is returning a custom object called UserSettings In my
I have a user object called UserSystem, which is created by a static factory
I have an object called Review which :belongs_to two objects: Users and Vendors. In
I created WCF service that returns a custom object called XmlElementTreeNode. This is what
According to MSDN (http://msdn.microsoft.com/en-us/library/dd487208.aspx), there is an object called DbDataReader that is created in
I have an object called Job that belong to another object called client in
I have an object called Person that has the following properties: int id; Name

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.