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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:50:17+00:00 2026-06-13T05:50:17+00:00

I need a List of items with sharable behavior. Example: Person class has List<PhoneNumber>

  • 0

I need a List of items with sharable behavior.

Example:

Person class

has List<PhoneNumber>
where only one PhoneNumber is bool IsPrimary
same for other items
has List<EmailAddress>
has List<Address>

Imagine each item (PhoneNumber, EmailAddress, Address) share the same interface ICanBePrimary which contains the requirement of one property bool IsPrimary and when in a List<ICanBePrimary> only one item in the list can have a true value for IsPrimary.

  • 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-13T05:50:18+00:00Added an answer on June 13, 2026 at 5:50 am

    The cleanest approach would be to hide a list behind a class that lets you enumerate over the content, and provides additional methods for identifying the primary item:

    class AddressList : List<Address> {
        private int indexOfPrimaryAddress = 0;
        public Address PrimaryAddress {
            get {
                return this[indexOfPrimaryAddress];
            }
            set {
                indexOfPrimaryAddress = this.IndexOf(value);
            }
        }
        // Override more methods to make sure that the index does not become "hanging"
    }
    

    An even cleaner implementation would encapsulate the list inside your AddressList class, and expose only the methods that you want exposed:

    class AddressList : IList<Address> {
        private int indexOfPrimaryAddress = 0;
        private readonly IList<Address> actualList = new List<Address>();
        // Implement the List<Address> by forwarding calls to actualList
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need for example the number of list-items, that are NOT . ATM, I
Total Novice here. I have some list items. I need to add a class
In one of my projects I need to make list items drag/droppable between table
I often need to list items with various-sized images on the left and text
I`v come across a need where I want to create multiple list items from
I need to pull a list of items from a MySQL database and then
I have a list of items that I need to update on different intervals.
I get a list of items from my Repository. Now I need to sort
Hello :) I realy need your help here. I dynamically generate list of items
Given a list I need to return a list of lists of unique items.

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.