In C# langage .. When do we use the keywords #virtual #override #new .. What is the defference between them | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

In C# langage .. When do we use the keywords #virtual #override #new .. What is the defference between them

as i know in the base classe we declare the methodes using virtual .. and in the methodes of derived classes we use override and new .. but what is the defference between them 😳

16th Jun 2017, 12:40 AM
Zineb Ab
Zineb Ab - avatar
1 Answer
+ 4
in a very simple and short way: if you want the derived class redefine a method (replaces the method in base class with the method in derived class) use the virtual/override modifiers (virtual in base class and override in derived class). but if you want to use the base class method, use the new modifier in derived class. just be carefull of relations between classes in polymorphisms.
16th Jun 2017, 10:16 AM
Saeede
Saeede - avatar