![]() ![]() Derived to Baseįollowing is the code that will convert an ICollection of derived objects to an ICollection of base objects: #region DERIVED TO BASE Unfortunately, neither of these is statements is allowed. It seems reasonable that you could convert a collection of derived objects to a collection of base objects: ICollection icollA2 = icollB Īnd maybe even convert a collection of base objects to a collection of derived objects, with a proper cast: ICollection icollB2 = ( ICollection)icollA Now imagine two generic List collections and ICollection interfaces: List collA = new List() Unfortunately, C# currently does not support generics variance, which would allow inheritance of generic types.įor example, imagine two classes: public class A ![]() Provides links to feature documentation for C#, Visual Basic, and Visual C++, and to supporting technologies such as reflection.As discussed in a previous article, Generics provides the ability to create strongly-typed collections in C#. ![]() Hashtable and Dictionary Collection Typesĭescribes the features of generic and nongeneric hash-based dictionary types.ĭescribes classes that provide sorting functionality for lists and sets.ĭescribes the generics feature, including the generic collections, delegates, and interfaces provided by. NET, including stacks, queues, lists, arrays, and dictionaries. Related topics Titleĭiscusses the various collection types available in.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |