---
title: "Understanding the different generic collections in .NET (List<T>, BindingList<T>, Collection<T>)"
url: "https://osherove.com/blog/2006/7/18/understanding-the-different-generic-collections-in-net-listl.md"
canonical: "https://osherove.com/blog/2006/7/18/understanding-the-different-generic-collections-in-net-listl.html"
published: "2006-07-18T01:21:00"
updated: "2006-07-18T01:21:00"
tags: [".NET", ".Net 2.0"]
author: "Roy Osherove"
description: "An innocent question came up in one fo the mailing lists I subscribe to. It was about when would you want to derive from the various generic collections in the framework. That also prompted another discussion about the…"
usage: "Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page)."
license: "https://creativecommons.org/licenses/by/4.0/"
---

# Understanding the different generic collections in .NET (List\<T\>, BindingList\<T\>, Collection\<T\>)

By Roy Osherove July 18, 2006 In [.NET](https://osherove.com/blog/category/net), [.Net 2.0](https://osherove.com/blog/category/net-2-0)

**Historical article** · Originally published July 18, 2006; technical details may be outdated.

An innocent question came up in one fo the mailing lists I subscribe to. It was about when would you want to derive from the various generic collections in the framework. That also prompted another discussion about the various kinds of generic collections in .NET you shoudl be aware of, which I think most people can't really tell the difference between when and where to use which of them. So here are parts of that discussion, quoted.

First, some reasons you'd want to derive from a generic collection .NET:

[Bill McCarthy](http://msmvps.com/blogs/bill/) writes:

"Custom sorting,
Validation,
Factory methods,
AddRange capabilities,
Custom serialisation,
Event hooking/raising
Delayed fetching (caching)"

and adds some more about the various collections:

"Well what I tell folks is they need to know 3 "lists".

- **List(Of)  : List<T>**
- **Collection(Of) :  Collection<T>**
- and **BindingList(Of).  : BindingList<T>**

I tell them to use: -

- **List(Of)** anywhere they use to use ArrayList, or anywhere they are ReDim'ing an array. But not to expose this outside of a class generally as it exposes a lot of methods that can change the internal data (e.g Sort)
- **BindingList(Of)** If they are using the collection for binding in Windows.Forms (or ASP.NET) then they should use BindingList. But they will often need to inherit from it, and override some methods (e.g sorting)
- **Collection(Of).** When not using binding, and you want to control what methods are exposed, and or intercept when objects are added or removed, you should derive from Collection(Of)

Of course there's others they need to know such as Dictionary and ReadOnlyCollection. "

And [Rocky Lhotka](http://lhotka.net/) adds to that discussion:

"In CSLA .NET I created my own generic collection classes because I needed to extend the behaviors of IBindingList(Of T) in various ways. The additional requirements include:

\* Persistence (some objects know about databases)
\* Sorting
\* Filtering

Those last two are interesting (I think), because I was able to create SortedBindingList and now FilteredBindingList, which are "updatable views"
against any List(Of T) that add sorting or filtering respectively.

**Dim list As New List(Of String)
**_' add items to list
_**Dim sorted As New Csla.SortedBindingList(Of String)(list)
sorted.ApplySort()
**_' enumerate through the sorted list
_**For Each item As String in sorted
  Debug.WriteLine(item)
Next**

The result is sorted output of the list. Because it is generic, the sorted list works against any IList(Of T), including lists of simple or complex types (like CSLA .NET business objects). Even better, any changes you make to 'sorted' are automatically reflected in 'list' and visa versa. That's because SortedBindingList isn't a copy, it is a view into the actual underlying list object.

You could envision similar constructs based around tree structures - I'd love to build a Red-Black Binary Tree along the lines of SortedBindingList to provide a balanced binary tree "view" of data in a list.

Also, I've been unable to determine for sure whether Queue(Of T) uses efficient multi-threaded reader-writer locking, but I don't think it does.
For some applications, having separate thread locking on the head and tail of the queue becomes important, but I think Queue(Of T) just uses a simplistic write lock scheme on the whole queue... That's harder to get right, but would be another reason to create your own generic collections."

## More in .NET

[All posts in .NET](https://osherove.com/blog/category/net)

- Aug 16, 2006

    ### [SharpRobo - Winform UI Unit Testing made easier?](https://osherove.com/blog/2006/8/16/sharprobo-winform-ui-unit-testing-made-easier.html)

- Aug 6, 2006

    ### [2 Day Architecture & SOA Course - Sound Interesting?](https://osherove.com/blog/2006/8/6/2-day-architecture-amp-soa-course-sound-interesting.html)

- Jun 27, 2006

    ### [ORMappers.Com is open for business (sort of)](https://osherove.com/blog/2006/6/27/ormapperscom-is-open-for-business-sort-of.html)

- Jun 19, 2006

    ### [A Simple Version Control Strategy Using Team System](https://osherove.com/blog/2006/6/19/a-simple-version-control-strategy-using-team-system.html)


---

## About the author

**Roy Osherove**: Senior Solutions Architect at AWS working on AI for production and AI-driven development; author of The Art of Unit Testing and Elastic Leadership, with about 20 years of consulting and training on unit testing, TDD, team leadership and continuous delivery.

### Sites

- [RobotPaper](https://robotpaper.ai/): This blog: AI patterns and anti-patterns, AI and coding agents, and engineering leadership.
- [osherove.com](https://osherove.com): Roy's personal site. Author of The Art of Unit Testing and Elastic Leadership; consulting and training on unit testing, TDD, team leadership and continuous delivery, plus about 20 years of blog posts.
- [The Art of Unit Testing](https://www.artofunittesting.com): The Art of Unit Testing, 3rd Edition (Manning): readable, maintainable, trustworthy unit tests, plus TDD workshops in C#, JavaScript, Java and Kotlin.
- [5whys.com](https://www.5whys.com): Roy's writing on software team leadership: self-organizing teams, surviving chaos, learning mode and the Elastic Leadership model.
- [Pipeline Driven](https://pipelinedriven.org): Continuous delivery and DevOps practices: build patterns, pipeline-friendly testing, DevOps metrics and enterprise DevOps.
- [Elastic Leadership](https://www.elasticleadership.com): Elastic Leadership, Roy's framework for software team leaders (survival, learning and self-organizing modes).

### Social

- X: https://x.com/royosherove
- LinkedIn: https://www.linkedin.com/in/osherove/

### Contact

- Contact form: https://forms.gle/jQSx5KoXvrVA1JCK7

### License

Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page). License: https://creativecommons.org/licenses/by/4.0/
