Covariance and Delegates in .Net 2.
I came across this little nugget in .Net 2 dealing with covariance, an object-oriented principle, and delegates. In a nutshell, covariance in .Net 2 allows you to build a one delegate that can point to methods returning different class types related by object-oriented inheritance. Please note the code below:

public class Book
{//...code here}

public class HistoryBook : Book
{//...code here}

class Program
{
            // with covariance one delegate may point to a method that returns a
            // a base class such as Book or a derived type such as HistoryBook, which
            // derives from Book.
            public delegate Book GetNewBookDelegate();        

            //target method of Book delegate
            public static Book GetABook()
            { return new Book(); }

            //target method of Book delegate
            public static HistoryBook GetNewHistoryBook()
            { return new HistoryBook(); }        

            static void Main(string[] args)
            {
                        GetNewBookDelegate bookDelegate =
                                new GetNewBookDelegate(GetABook);
                        Book book = bookDelegate();

                        // Covariance allows a derived type to be returned
                        // from the target method of the delegate
                        GetNewBookDelegate historyBookDelegate =
                                new GetNewBookDelegate(GetNewHistoryBook);
                        //note the explict cast below to get the derived type
                        HistoryBook historyBook = (HistoryBook)historyBookDelegate();
            }
}

This is a very cool "code re-use" feature!

Valid XHTML 1.0 Transitional