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)?