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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:07:43+00:00 2026-06-15T02:07:43+00:00

A quick example: Tom, Mary and John say I want an apple Tom and

  • 0

A quick example:

Tom, Mary and John say "I want an apple"
Tom and John say "I want a race car"
John and Mary say "I want a pretty dress."

DataStructure[Tom] returns --> "I want an apple";"I want a racecar";
DataStructure[Mary] returns --> "I want an apple";"I want a pretty dress";

What is the idea data structure? If the number of keys or values can change? Where I could presumably type DataStructure.Add(Mary, “New String); or DataStructure.AddWithNewKey(“Timmy”, List)?


Is there a better way than keeping a list or array of strings for each person?


In the comments below, I was confused as to why it would matter if the data was known at compile time or was purely dynamic. Jon has pointed out that if the data was to be built dynamically, the ideal would be a dictionary related the string values to the people. Otherwise his linq solution is quite nice.

  • 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-15T02:07:46+00:00Added an answer on June 15, 2026 at 2:07 am

    It sounds like you want an ILookup – a map from keys to multiple values. You can create this using the ToLookup method in LINQ. Alternatively, if you want to build something similar up in a mutable fashion, you can use a Dictionary<,> where the type of the value is a list of some kind, e.g. Dictionary<string, IList<string>>. This is just a bit more fiddly than using a lookup, and doesn’t behave as elegantly for missing keys.

    The best solution will partly depend on how you’re getting your data, mind you. It’s not really clear from your example.

    EDIT: You wouldn’t want a Lookup<bool, StringInfo>. You’d want a Lookup<Person, string> where Person was an enum of Tom, Mary, John or something similar. The fact that these are hard-coded as properties is awkward, but not insurmountable. I would add a utility method like this:

    static IEnumerable<Person> GetPeople(StringInfo input)
    {
        // I don't normally use this formatting, but it's cleaner than the
        // alternatives in this particular case.
        if (input.Mary) yield return Person.Mary;
        if (input.Tom) yield return Person.Tom;
        if (input.John) yield return Person.John;
    }
    

    You can then use:

    var lookup = allStringInfos
           .SelectMany(info => GetPeople(info),
                       (info, person) => new { text = info.stringInfo, person })
           .ToLookup(pair => pair.person,
                     pair => pair.text);
    

    Then:

    foreach (string value in lookup[Person.John])
    {
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone post a quick example (implementation) of the stateMachine? The concept is pretty
Lets say I have the following xml (a quick example) <rows> <row> <name>one</name> </row>
Here's a very quick example for my problem: http://img19.imageshack.us/img19/3575/workertool.png (I'm not allowed to post
Quick question. For example, working with a some-what larger case of ~1000 options: which
For example: In my table I have text field with following text: The quick
Just a quick preparation for my exam, for example I have: f(x) = 5x<sup>2</sup>
I have quick question about text parsing, for example: INPUT=a b c d e
Can someone provide a quick top level explanation of how Valgrind works? An example:
Just a quick example: <p> <span class=example></span> <input type=text name=e_name id=e_id /> </p> <script
Can someone show a quick example on how to use NSTask and NSPipe in

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.