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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:13:08+00:00 2026-06-05T17:13:08+00:00

new to c#. I’m trying to make a simple system where I can search

  • 0

new to c#.
I’m trying to make a simple system where I can search through a list of objects and when it belongs to a certain ID. Put it in a List/ArrayList so I can read it out/do anything else.

Each “item” has a locationID. When I enter this location and press “look”. The program should check which location I’m in and take out only the “items” with the same ID.

In practise. The list of items is going to be quite big (and locations too). So it seems a waste of processing to go through the list again and again. That’s why I thought of using a dictionary. But I don’t seem to be able to access multiple entries in the dictionary, only at one specific place.

for example:

Dictionary<string, int> itemLoc = new Dictionary<string, int>();
itemLoc.Add("pen", 011);
itemLoc.Add("paper", 011);
itemLoc.Add("tv remote", 012);

//print everything in location 011

Sorry for a lack of code. I’m still figuring out how to get my head around this. I’ve been researching ArrayLists, Lists, Hashtables, and these Dictionaries. But with none I’ve been able to achieve what I’m looking for effectively.

I could do a foreach, and check each entry. But like mentioned above. That would seem a waste of processing.

Any idea’s or tips?
A nudge in the right direction code-wise would be really appreciated.

  • 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-06-05T17:13:10+00:00Added an answer on June 5, 2026 at 5:13 pm

    You haven’t given us enough information as to the constraints of your problem. A Dictionary<string, List<string>> will perform faster, but you haven’t identified if you can have multiple items in multiple locations (for example, can “paper” be in 011 and 012 or just in 011?) In that case, every time you add you will have to make sure that item is not already in another location.

    A very simplified approach would be to break it down very simplistically, and optimize based on your results.

    class MyItem
    {
        public string Name { get; set; }
        public string Location { get; set; }
    }
    
    class Program
    {
        static void Main(string[] args)
        {
            List<MyItem> myItems = new List<MyItem>()
            {
                new MyItem() { Location = "011", Name = "pen" },
                new MyItem() { Location = "011", Name = "paper" },
                new MyItem() { Location = "012", Name = "tv remote" }
            };
    
            var specificItems = myItems.Where(f => f.Location == "011");
    
            foreach (var item in specificItems)
            {
                Console.WriteLine(item.Name);
            }
    
            Console.Read();
        }
    }
    

    Once you perform your benchmark, you can consider switching it to something (perhaps a Dictionary<string, List<string>>

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

Sidebar

Related Questions

New to Node.js and Express, I am trying to understand the two seems overlapping
New programmer here, I am trying to understand and break down this code below
New to wordpress and web design in general. I'm trying to setup a website
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
New to objective-c and I just can't find the answer to this question anywhere.
New to files in C, trying to read a file via fread Here's the
New to SharePoint. I'm trying to upload a document to SharePoint using it's CopyIntoItems
New to linux and trying to escape doing this the hard way. I have
New to Web2py, so my question might not be too clear. I'm trying to
New to javascript - I'm trying to generate random user ID's for my selenium

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.