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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:49:33+00:00 2026-05-22T18:49:33+00:00

I just wanna ask what best way to work around a Two-Dimensional Array (2

  • 0

I just wanna ask what best way to work around a Two-Dimensional Array (2 Columns) which would store: CandidateName and their respective VoteCount.

What I want exactly to do is to, accept an input from the user say: VOTE John 10 wherein John is the name of the candidate and 10 is the votes that he wanna give him. So I need to store {John, 10} into my array. However, after this my program would once again ask the user for votes so if I enter VOTE Doe 15, the entry {Doe, 15} would then be added to the array. If the user enters VOTE John 2, my array needs to be updated and thus the new value would be {John, 12}.

Currently I use two arraylists: CandidateName and VoteCount and I just rely on their index for pairing. However, this isn’t really reliable so I’m trying to find another way on how to solve this. However, I’m not really a big fan of multi-dimensional arrays.

Can someone please point me out to a good way on how to achieve 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-22T18:49:34+00:00Added an answer on May 22, 2026 at 6:49 pm

    You should use an Associative Array. In the case of C#, such a collection is the Dictionary.

    var votes = new Dictionary<string, int>();
    votes["John"] = 10;
    votes["Bob"] = 20;
    votes["John"] = 15; // replaces earlier setting
    

    If you want to add to the exisiting vote, you will need to check if there is an existing value:

    private Dictionary<string, int> votesByPeep; // initialized in constructor
    
    private void AddVotes(string peep, int votes)
    {
        if (this.votesByPeep.ContainsKey(peep)
        {
            this.votesByPeep[peep] += votes;
        }
        else
        {
            this.votesByPeep[peep] = votes;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

wanna ask for your opinion. What would be the best object (Array, List<>, Collection,...)
I just wanna ask if there's a way where I could put an object
I just wanna ask if there's a way in C#/ASP.NET to create 'dynamic' tables/fields
I just wanna ask what would be better approach to supply these objects in
I just wanna ask how can I make a form with two buttons that
I just wanna ask best practice supposed I have three tables. posts, categories, post_Categories.
I just wanna ask what is the efficient way to get the week numbers
I just wanna ask your opinion/suggestion on how to 'terminate' a running application/process is
I just wanna ask if there's a possibility to retrieve the contents of a
i am using vb.net i just wanna ask if we can place a picture

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.