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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:37:40+00:00 2026-05-13T23:37:40+00:00

In my project I use quite complicated (and nested) collection: List<Pair<List<Pair<double>>, double>> myCollection As

  • 0

In my project I use quite complicated (and nested) collection:

List<Pair<List<Pair<double>>, double>> myCollection

As I use it in whe same way in several places in my project, I would like to convert it to new class. But I have some doubts…

What is the best way to handle this sort of collections, create an inner field and pass as public only selected items:

public class MyComplicatedCollection
{
    private List<Pair<List<Pair<double>>, double>> myInnerCollection = null;

    // Here come some constructors, data accessors etc... only to those elements which I would like to pass as public.
}

Or maybe in other way, by deriving the original collection:

public class MyComplicatedCollection : List<Pair<List<Pair<double>>, double>>
{

    // Here come some constructors, 
    // Most of the data accessors are given "out of the box"
}

Second way seems to be easier, but not as safe as the first way. The other thing is performance – these collections are really big and I need quite fast access to it – it is crucial.

And the second question: if the second way is better… For List there is a constructor when you can populate your collection by passing any ICollection. Is there any easy way of creating such constructor for my class, or do I need to populate my collection element by element (or using AddRange method)?

  • 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-13T23:37:40+00:00Added an answer on May 13, 2026 at 11:37 pm

    When in doubt use composition. Inheritance is hard to do right and you should only use it if you must have a IS-A relationship between your new type and the base/composed type. In this case I think that composition (i.e. your first example) is the best solution.

    Composition gives you the flexibility to build your type with whatever public interface you desire. Inheritance dictates that interface to you and also creates a tight coupling between your new type and its base type which can make future modifications difficult.

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

Sidebar

Related Questions

In a project we use PartialView and View on the same action, depending how
I will be creating a project that will use dictionary lookups and inserts quite
we have quite a few projects that use the same codebase (backend code). Just
We're working on quite big project and decided use GIT for version control. I've
I'm making use of an open source project that is changing quite frequently. It
When I compile our project use Delphi 2010 Trial, there has a fatal error
I try to run my project in windows. Project use android ndk. I install
For my project I use rake test for testing my libs. For example, I've
In our project we use Zend Framework Model generator, which produces something like this
In a project i use the following code to open a window: window.open(href, 'mysite'

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.