Sunday, May 23, 2010

Generic types like BindingList<T> are very powerful because they allow a developer to easily create a strongly typed instance of the generic type. For instance

BindingList<string> myStringList;

defines a strongly typed collection of type string.

Similarly BindingList<int> myIntList;

defines a strongly typed collection of type int. Since both myStringList and myIntList are “of type” BindingList<T>, you might think they are polymorphic—that you could write one method that could act on both fields. But you can’t. Generic types are not inherited, and thus do not come from the same type. This is highly counterintuitive at first glance, but nonetheless is a fact of life when working with generic types.

In order to treat instances of a generic type polymorphically, or to do type checks to see if those instances come from the same type, the generic type must inherit from a non-generic base class or implement a non-generic interface. In the case of BindingList<T>, the generic type implements IBindingList. So both myStringList and myIntList can be treated as IBindingList types.

C# fast-food by:
Eng.Waleed abou-zaid
Senior Software Developer
Harf Information Technology
MCSD.Net,MCAD.Net,MCP,A+,N+ certified
walid.abouzaid@gmail.com



1 comments:

net performance said...

The main thing in Binding List is that You can always write an adapter for it so it uses List Collection View instead of Binding List Collection View.