M
Marcel Hug
Hi NG !
I'm new in C# and I'm reading a book about the fundamentals and concepts.
In the chapter Methods it's written to use virtual, if i would like to
override the method in a subclass. This I've to do by using override.
It's also written, that's possible to "hide" the base class method by
using the new key word.
Because I've already written some C# code and I didn't know anything
about override and virtual I didn't use it, but it have been worked. So
i wrote some test code without using override and virtual to check this
aspect. It runs.
So now I have some question:
1.) Why do I have to use the override and virtual keys words, if it runs
without ? Is it for better readability ?
2.) When do I've to use virtual and override and when new ? I mean is
there a rule which describes in this case it should be used virtual and
override and in some other cases better use new ?
Thanks
Regards
Marcel
I'm new in C# and I'm reading a book about the fundamentals and concepts.
In the chapter Methods it's written to use virtual, if i would like to
override the method in a subclass. This I've to do by using override.
It's also written, that's possible to "hide" the base class method by
using the new key word.
Because I've already written some C# code and I didn't know anything
about override and virtual I didn't use it, but it have been worked. So
i wrote some test code without using override and virtual to check this
aspect. It runs.
So now I have some question:
1.) Why do I have to use the override and virtual keys words, if it runs
without ? Is it for better readability ?
2.) When do I've to use virtual and override and when new ? I mean is
there a rule which describes in this case it should be used virtual and
override and in some other cases better use new ?
Thanks
Regards
Marcel