Note: the virtual and abstract methods cannot be declared as private.
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingSystem.Threading.Tasks;6 usingSystem.Collections;7 8 namespaceConsoleApplication19 {Ten One classEmployee A { - Private string_name; - the PublicEmployee (stringname) - { - This. _name =name; - } + - Public stringName + { A Get at { - return This. _name; - } - } - - Public Virtual voidstartwork () in { -Console.WriteLine ("{0} starts work.", This. _name); to } + } - the classManager:employee * { $ PublicManager (stringName):Base(name)Panax Notoginseng { - the } + A Public Override voidstartwork () the { +Console.WriteLine ("{0} starts to Distrubit tasks",Base. Name); - } $ } $ - classSecretary:employee - { the PublicSecretary (stringname) -:Base(name)Wuyi { the - } Wu - Public Override voidstartwork () About { $Console.WriteLine ("{0} starts to help",Base. Name); - } - } - A classSeller:employee + { the PublicSeller (stringname) -:Base(name) $ { the the } the the Public Override voidstartwork () - { inConsole.WriteLine ("{0} starts to sell",Base. Name); the } the } About the classAccountant:employee the { the PublicAccountant (stringname) +:Base(name) - { the Bayi } the the Public Override voidstartwork () - { -Console.WriteLine ("{0} starts to compute",Base. Name); the } the } the the class Program - { the Static voidMain (string[] args) the { theEmployee[] es =Newemployee[5];94 thees[0] =NewEmployee ("Tim"); thees[1] =NewManager ("Gan"); thees[2] =NewSecretary ("Kate");98es[3] =NewSeller ("Jim"); Aboutes[4] =NewAccountant ("Tata"); - 101 foreach(Employee Einches)102 {103 e.startwork ();104 } the 106 Console.readkey ();107 }108 }109}
View Code
C # Video-virtual method, virtual