There is a virtual method in a library that my C# project references. How can I override this method in another class within 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 totally forgetting that this class didn’t inherit from the libraries class messed me up, it was late 🙂
You should study a bit about OOP (and inheritance in particular) before getting down to any serious coding. For quick reference, here’s an example of how to override a method:
You should observe that the signature of the overriding method (including its name) must be the same. The derived class, on the other hand, may (and typically should, for clarity) be named differently.