R
Rafael Veronezi
I have some questions about override in inheritance, and virtual members.
I know that you can you override a method by two ways in C#, one, is
overriding with the new keyword, like:
public new bool Equals(object obj) {}
Another is using the override keyword, like:
public override bool Equals(object obj) {}
And my question is, what's the main diference of using one or another? Also,
I know about a keyword called virtual. I thought that the virtual keyword is
used to identify a method that can be overriden... I'm not sure about that,
I would like to know a better explain of virtual methods, cause I think that
using the new keyword, you can override any method in the inhereted class
(not sure about that)...
I wrote a struct where I override the Equals method, I did that first using
the override keyword, but the compiler throws a warning saying that I would
need to override the GetHashCode method too, why this? I would like to know
the diference about those declarations, and the real definition of virtual
methods!
Thanks guys!
I know that you can you override a method by two ways in C#, one, is
overriding with the new keyword, like:
public new bool Equals(object obj) {}
Another is using the override keyword, like:
public override bool Equals(object obj) {}
And my question is, what's the main diference of using one or another? Also,
I know about a keyword called virtual. I thought that the virtual keyword is
used to identify a method that can be overriden... I'm not sure about that,
I would like to know a better explain of virtual methods, cause I think that
using the new keyword, you can override any method in the inhereted class
(not sure about that)...
I wrote a struct where I override the Equals method, I did that first using
the override keyword, but the compiler throws a warning saying that I would
need to override the GetHashCode method too, why this? I would like to know
the diference about those declarations, and the real definition of virtual
methods!
Thanks guys!