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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:41:23+00:00 2026-05-15T08:41:23+00:00

I have a class that has an internal list of other objects like so:

  • 0

I have a class that has an internal list of other objects like so:

public class Parent
{
    List<Child> _children;
}

where Child say looks like this:

public class Child
{
    public string Name;
}

What I want to do is set up parent where the members of _children can be accessed like so:

...
Child kid = parentInstance["Billy"]; // would find a Child instance 
                                     // whose name value is Billy
...

Is this possible? I could obviously do something like this:

Child kid = parentInstance.GetChild("Billy");

But I prefer the array/dictionary like syntax. This isn’t a big deal if it isn’t, and I don’t want to have to jump through a million hoops for what amounts to syntactic sugar.

  • 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-15T08:41:23+00:00Added an answer on May 15, 2026 at 8:41 am

    You could define an indexed property to the Parent class:

    public class Parent
    {
        List<Child> _children;
    
        public Child this[string name] 
        {
            get
            {
                return (_children ?? Enumerable.Empty<Child>())
                    .Where(c => c.Name == name)
                    .FirstOrDefault();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that has an list<Book> in it, and those Book objects
I have a class that has an list<Book> in it, and those Book objects
I have a Class that has a private variable with a public setter/getter function:
I have a class contain many variables, something like that class test { internal
I have a manager class maintaining a list of objects. Each Object has a
I have a class that has several member classes as attributes. The constructor of
I have a class that has a vector member variable, which I fill up
I have a class that has an inner struct/class (I have decided which yet,
I have a class that has a property that I need to stub. I
I have a class that has a method: -(NSInteger) getCityCountForState:(NSString *)state CityArray:(NSMutableArray *)cityArray {

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.