14.5. Custom Collections

The .NET Collections library does not contain nearly as many classes and interfaces as the java.util package. The Collections library currently has no support whatsoever for sets. Sometimes you must roll your own collections. You do so by implementing some of the System.Collections interfaces.

In the next two listings we will try to write a C# version of the java.util.LinkedHashMap, a special HashMap introduced in JDK 1.4. Unlike the ordinary HashMap, this new one stores the key-value pairs in the order in which they are added to the map. The ability to retain this order is critical when, say, you are fetching data from a database and that data is already sorted according to certain criteria and you don't want to destroy ...

Get .NET for Java Developers: Migrating to C# now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.