E
Ethan Strauss
Hi,
This seems really basic, but I can't figure it out.
What is the difference between an inherited class overriding a base
class method and an inherited class creating a "new" method.
For example, I have a class and inherited class as follows
class Units
{
//...
public virtual bool Equiv(object obj)
{
//...
}
}
class NumberWithUnits : Units
{
//...
public override bool Equiv(object obj)
{
//...
}
new public bool Equiv(object obj)
{
}
}
Why might I want to new vs override in the method?
When I first started on this, I was actually overriding Equals and I got
weird results when I defined a method as
public bool override Equals(object obj, double tolerance)
This method did not seem to get called under any conditions until I removed
the override and added "new". Not quite sure what that means.
Thanks,
Ethan
This seems really basic, but I can't figure it out.
What is the difference between an inherited class overriding a base
class method and an inherited class creating a "new" method.
For example, I have a class and inherited class as follows
class Units
{
//...
public virtual bool Equiv(object obj)
{
//...
}
}
class NumberWithUnits : Units
{
//...
public override bool Equiv(object obj)
{
//...
}
new public bool Equiv(object obj)
{
}
}
Why might I want to new vs override in the method?
When I first started on this, I was actually overriding Equals and I got
weird results when I defined a method as
public bool override Equals(object obj, double tolerance)
This method did not seem to get called under any conditions until I removed
the override and added "new". Not quite sure what that means.
Thanks,
Ethan