Geeks With Blogs
Prasanna's Blog BizTalk, WCF, C# and Software Factories

A generic class that uses parameterized types, like MyBase<T>, is called an open-constructed generic. A generic class that uses no parameterized types, like MyBase<int>, is called a closed-constructed generic.

You may derive from a closed-constructed generic; that is, you may inherit a class named MyDerived from another class named MyBase, as in:


public class MyDerived<T> : MyBase1<int>

You may derive from an open-constructed generic, provided the type is parameterized.

For example:

public class MyDerived<T> : MyBase<T> is valid, but


public class MyDerived<T> : MyBase<Y> is not valid since Y is also a parameterized type.

Note: Non-generic classes may derive from closed-constructed generic classes, but not from open-constructed generic classes. That is,

public class MyDerived : MyBase<int> is valid, but


public class MyDerived : MyBase<T> is not valid.

-------

Posted on Thursday, March 13, 2008 12:49 PM BizTalk, WCF, Design Patterns, C#, Software Factories , C# , general | Back to top


Comments on this post: Generics & Inheritance

# re: Generics & Inheritance
Requesting Gravatar...
Buddy can you tell me some real world examples where we will be using such a generic inheritance.
Left by Ananda on Apr 29, 2008 8:28 AM

Your comment:
 (will show your gravatar)


Copyright © Prasanna Krishnan | Powered by: GeeksWithBlogs.net