Overriding a method from a library

The library has a virtual method that references my C # project. How can I override this method in another class in my application?

Example:

namespace TheLibary
{
   class SomeClass
   {
      public virtual void TheMethod()
      {
           //Do Stuff
      }
   }
}

      

Then in my project:

using theLibary;
namespace TheProject
{
   class SomeClass
   {
       public override <Help>
   }
}

      

Edit: Confusion and complete forgetting that this class did not inherit from the library class messed me up, it was already too late :)

+3


source to share


1 answer


You should learn a little OOP (and inheritance in particular) before getting into serious coding. For quick reference, this is an example of how to override a method:

namespace TheDll
{
    public class SomeClass
    {
        public virtual void TheMethod()
        { }
    }
}

namespace TheProject
{
    public class DerivedClass : SomeClass
    {
        public override void TheMethod()
        { }
    }
}

      



You should notice that the signature of the override method (including its name) must be the same. On the other hand, a derived class can (and usually, for clarity) be named differently.

+4


source







All Articles