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:
namespace TheDll
{
public class SomeClass
{
public virtual void TheMethod()
{ }
}
}
namespace TheProject
{
public class DerivedClass : SomeClass
{
public override void TheMethod()
{ }
}
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With