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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:58:20+00:00 2026-05-29T10:58:20+00:00

Taking beginning Data Structures in C# class, trying to make a searchable arraylist of

  • 0

Taking beginning Data Structures in C# class, trying to make a searchable arraylist of a string and an int referenced together (name and number).I need to be able to search for the name, and retrieve both the name and the number it’s attached to. I was told I can use an arraylist of structs, but have never used structs. Any simple explanation how, or a better way?

Thank you in advance.

  • 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-29T10:58:20+00:00Added an answer on May 29, 2026 at 10:58 am

    You should probably be using something like a hash for this as an ArrayList of structs is a bit square peg round hole.

    You declare a struct just like a calss.

    public struct Foo {
        public String Bar { get; set; }
        public Int32  Biz { get; set; }
    }
    

    And you can make an array list of then as you would with any type

    var list = new ArrayList();
    list.add(object);
    

    The other issue here is that ArrayList isn’t generic, it will cast everything to Object which means you will have to cast everything back to type Foo to work with it.

    var foo = (Foo)list.item(0);
    

    You would be much better off, if you have to go the route of List instead of Hash using a generic list class like List and declaring its type;

    var list = List<Foo>();
    var foo = new Foo { Bar = "Hello World", Biz = 1 };
    list.add(foo);
    

    As for searching a list, I prefer to use the LINQ methods, because they are quick to code and easy to read.

    var matches = list.Where( x => x.Biz > 1 );
    

    But if you cannot do that then iteration always works

    var matches = new List<Foo>();
    foreach ( var foo in list ) {
        if ( list.Biz > 1 ) {
            matches.add(foo);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a Java novice taking a beginning programming class and I'm trying to finish
I am taking a beginning C++ class, and would like to convert letters between
Suppose I have data Foo = A String Int | B Int I want
I'm taking a beginning Java class and an assignment requires that I write a
I'm trying to develop a way of taking an entity with a number of
I am taking a database class and at the beginning of the lab section
I'm taking an Algorithms class and the latest homework is really stumping me. Essentially,
Taking over some code from my predecessor and I found a query that uses
Taking shs's question a step further... Why isn't all government sponsored software open source?
Taking advice from this post , I purchased a copy of 'The C Programming

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.