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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:17:45+00:00 2026-05-27T11:17:45+00:00

For example, I have in my application a list of a type what has

  • 0

For example, I have in my application a list of a type what has a persons name as it’s name and holds two values. The name of the type is the persons name and the type contains only their age and number of std’s.

My first idea was to make a class of Persons with Age and NumStds properties where Age and NumStds is required in the constructor and the create a List which I can add to.

class Person
{
    public string Name { get; set; }
    public int NumSTDs { get; set; }
    public int Age { get; set; }

    public Person(string name, int age, int stds)
    {
        Name = name;
        Age = age; 
        NumSTDs = stds; 
    }
}

static void Main(string[] args)
{
    List<Person> peoples = new List<Person>();
    peoples.Add(new Person("Julie", 23, 45)); 
}

I was just wondering if there is a data structure where I could just refer to the elements in the List<> by their Name and have the properties attached to them come along for the ride. Like I could say

people.Remove(Julie) 
  • 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-27T11:17:46+00:00Added an answer on May 27, 2026 at 11:17 am

    Have a look at the KeyedCollection<TKey, TValue> Class.

    KeyedCollection<TKey, TValue> Class

    Provides the abstract base class for a collection whose keys are embedded in the values.

    You need to derive your own collection class from this abstract class, e.g.

    class PersonCollection : KeyedCollection<string, Person>
    {
        protected override string GetKeyForItem(Person item)
        {
            return item.Name;
        }
    }
    

    Example:

    static void Main(string[] args)
    {
        var peoples = new PersonCollection();
        var julie = new Person("Julie", 23, 45)
        peoples.Add(julie);
    
        people.Remove(julie);
        //  - or -
        people.Remove("Julie");
    }
    

    Note that the Name property of your Person class should be immutable (read-only).

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

Sidebar

Related Questions

I have two classes in a PHP application, B extending A for example. Class
I have an MVC application. Say for example if we have a dropdown Cars
i have this application but how to use its? and example for 7-zip can?
Let's have an example. In application I have a tab bar controller. Tab bar
I have a .NET application that uses some API calls, for example GetPrivateProfileString .
I am developing an application, and have URLs in the format www.example.com/some_url/some_parameter/some_keyword . I
I have an application where I have a main viewmodel whose view contains a
In our application we have an object that receives attributes at runtime. For example,
Let's say you have two instances of the same bean type, and you'd like
I have a list that contains many dictionaries. Each dictionary represents a change that

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.