ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button
  Writing Type-Safe Collections in C#
Subject:   Thanks!
Date:   2005-05-19 11:57:25
From:   EvanStein
Great article -- short, sweet, and after two years' time, the gift that keeps on giving.

Typed collections would be extremely handy if they were included in future versions of C#. While it's true that re-inventing the wheel can cause its own headaches, these workarounds can be fantastically helpful if used once or twice.

For instance, if a typed collection is designed for a class that's used all over an application, it promotes polymorphism and reuse. Equally important, the programmer can see the class members at design time without having to "box" and "unbox" everything by hand, or call unidiomatic functions.

Properties don't take indices in C#, and Microsoft recommends you write functions as a workaround -- kind of disappointing if you're a fan of elegance. So, it's up to you which workaround works best. If it doesn't grind things to a halt, there's a decided advantage in clear code! The clearest C# code is the code that looks like the rest of C#.

Though the author himself isn't sanguine about the whole thing, most of it is the worry about putting a loaded gun into the wrong hands. The rest, I suspect, is undue modesty! Thanks for the tip.