Click here to Skip to main content
15,885,278 members

Response to: Passing a generic class to a non generic method

Revision 2
The generic class could inherit from a non-generic class.
C#
public class NodeBase
{
    // Base class stuff here

    public virtual void NodeMethod()
    {
        // Do something
    }
}

public class Note<t> : NodeBase
{
    // Generic class stuff here

    public override void NodeMethod()
    {
        // Do something special
    }
}
Then you can hand it over to the method this way:
C#
public class classname
{
    public void SomeMethod( NodeBase node)
    {
        // Use methods declared in base class
        node.NodeMethod();
    }
}
Posted 7-Dec-11 20:35pm by lukeer.
Tags: