Fog Creek Software
Discussion Board




C# Generics - now!

I'm porting a fair amount of Delphi code to C#.  The code doesn't make much use of libraries - it basically involves classes that define elaborate data structures. Is pretty ugly because of all the casting that needs to happen because Delphi doesn't have typed collections. I know, it does, sort of, but I just don't want to set up all that machinery.

With the current Visual Studio, I have to chose between arrays and ArrayLists (or whatever), neither of which gives me the succinctness that I want.

Does Microsoft have something that I can use now? Please point me somewhere else if there is a better source for this information.

Or should I just go with Python, Lisp, etc? Performance would be great, but what I most need is readability and maintainability.       

Corporate Dork
Wednesday, February 18, 2004

System.Collections.Collectionbase. 

It provides an abstract class for making strongly-typed collections.  There are examples on MSDN.  Not nearly as cool as generics, though.  <g>

Robert Jacobson
Thursday, February 19, 2004

You can also use DictionaryBase (in the same namespace), to create dictionary-like behaviour.

The samples in MSDN show that it is trivial to set up.

I've used these base classes to create several strongly-typed collections and they seem to work beautifully.

Steve Jones (UK)
Thursday, February 19, 2004

http://www.google.be/search?q=C%23+typed+collection+generator&ie=UTF-8&oe=UTF-8&hl=nl&meta=

might give you some usefull stuff

Just me (Sir to you)
Thursday, February 19, 2004

http://www.ericjsmith.net/codesmith/

Chris Nahr
Thursday, February 19, 2004

I've converting collections from an old VB6 program to C#. After much googling, I found an article in The Code Project very useful for this.

http://www.codeproject.com/csharp/hashlistarticle.asp

This collection implements IDictionary, IEnumerable, and internal ArrayList, and a Hashtable. I found it very handy.

HTH!

Slartibartfast
Thursday, February 19, 2004

A second for CodeSmith. Until there's generics in .NET, then generative coding is the only way to go for this kind of stuff.

Brad Wilson (dotnetguy.techieswithcats.com)
Thursday, February 19, 2004

*  Recent Topics

*  Fog Creek Home