generic-collections

Sort List alternative in c#

I have a number of objects, all from the same class(ColorNum) Each object has 2 member variabels (m_Color and m_Number) Example: ColorNum1(Red,25) ColorNum2(Blue,5) ColorNum3(Red,11) ColorNum4(White,25) The 4 objects are in the ColorNumList List<ColorNum> ColorNumList = new List<ColorNum>(); Now I want to order the list so the obj...

C# - how to create an inherited generic collection from a factory method

I am trying to write a factory method that will create a derived instance of an abstract generic collection class. Here are the base classes ... abstract class ItemBase { } abstract class CollectionBase<T> : Collection<T> where T : ItemBase, new() { } ...and their derived classes ... class Item : ItemBase { } class ItemCollection :...

template style matrix implementation in c

From time to time I use the following code for generating a matrix style datastructure typedef double myType; typedef struct matrix_t{ |Compilation started at Mon Apr 5 02:24:15 myType **matrix; | size_t x;...

How to bundle extension methods requiring configuration in a library

Hi, I would like to develop a library that I can re-use to add various methods involved in navigating/searching through a graph (nodes/relationships, or if you like vertexs/edges). The generic requirements would be: There are existing classes in the main project that already implement the equivalent of the graph class (which contains...

Is there a collection in .NET that works as a dictionary and list at the same time?

What I want is basically a collection that's a hybrid of a dictionary and a list. I want a collection that I can add key/value pairs to (like a Dictionary), but at the same be able to retrieve the values (without the keys) in the same order I added them (like a List)? Does such a collection exists in .NET? Thanks ...

Why there isn't a ReadOnlyList<T> class in the System.Collections library of C#?

Reading about the problem of creating a read only primitive vector in C# (basically, you cannot do that), public readonly int[] Vector = new int[]{ 1, 2, 3, 4, 5 }; // You can still changes values I learnt about ReadOnlyListBase. This is a base class for containers of objects that let their positions be accessed but not modified. Even...

C# / .NET equivalent for Java Collections.<T>emptyList()?

What's the standard way to get a typed, readonly empty list in C#, or is there one? ETA: For those asking "why?": I have a virtual method that returns an IList (or rather, post-answers, an IEnumerable), and the default implementation is empty. Whatever the list returns should be readonly because writing to it would be a bug, and if some...