Thursday, December 15, 2005

Using Collections in .NET [UPDATED]

How and when to use the various collections and other aggregators or an array has been an ongoing question for me. There is/are a variety of classes in the FCL which provide collection-type containers. How do you decide which to use when? Here are some references I have found helpful. But no conclusions yet.

I think the discussions are good in the books of Francesco Balena, Jeff Richter, and others:
Authors I like include Ken Getz and Paul Sheriff, but I don' find articles by them on this.

Articles I have found:
Scott Mitchell has some articles at his 4GuysFromRolla site:
Chapter 2 (from his ASP.NET: Tips, Tutorials, and Code book) compares 5 types of collections: ArrayList, Hashtable, SortedList, Queue, and Stack. After discussing each one individuality he shows their similarities and demonstrates the use of the IEnumerator interface to access them.
Specialized Collections is a useful article at MSDN.
Not to mention his series An Extensive Examination of Data Structures at MSDN.

Related Blog Postings:
Collection classes and behavior by Yves Reynhout
Article: OOP and Security sometimes go hand in hand by Tobin Titus

The new version 2.0 of the Framework will apparently extend the functionality of collections. Obviously the availability of generics is significant; plus some new extensions to the actual object collection classes. No refs yet for them.

CodeSmith by Eric Smith may be a good way to generate code for collection classes. http://www.ericjsmith.com/codesmith/default.aspx

[Original post 5/15/2005]
Delegates in C# vs VB.NET down to the IL

3 Comments:

Blogger Allan Wolff said...

I found some more articles on this topic...

Rod Stepehns onn Rolling your own Strongly Typed Collections in a Hardcore VB 'VB-Helper' column:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnhcvb04/html/vb04l4.asp

5:15 AM  
Blogger Allan Wolff said...

I tried to find this by searching on Dictionary. Surprisingly I did not mention Dictionary in this posting. I should amend this to show some real observations, rather than just links.

1:39 PM  
Blogger Allan Wolff said...

Wow! That earlier comment link is wrong. It points to an artilce on "Working with Files and Directories" by Carl Ganz (December 2004). The article I meant to reference is "VB-Helper:Strong Stuff" in the March 200-4 issue. It is a pretty good review of creating strongly-typed classes in both VB6 and VB.NET. For VB6 shows the odd tricks needed to implement enumeration. Wrt VB.NET he shows how simple it is to inherit from CollectionBase, but then he goes on to discuss how VB.NET "also changes the purpose of a collection". "In previous versions of VB, you could access a collection's objects by either their indexes or their keys. In VB.NET, a collection doesn't have keys, so you can only access items using indexes (or a For Each loop)." For those kinds of functionality he shows two other types of collections that have bases you can inherit from - DictionaryBase and NameObjectCollectionBase. He doesn't discuss the relative performance of a Collection versus a Dictionary which I have seen mentioned elsewhere.

2:02 PM  

Post a Comment

<< Home