Virtual memebers:
Using System; Using System. Collections. Generic; Using System. LINQ; Using System. text; Namespace Leleapplication2 { Class Person { Public String Firstname { Get ; Set ;} Public String Secondname { Get ; Set ;} Public Virtual Void Display () {console. writeline ( " Person-{0}, {1} " , Firstname, secondname );} Public Virtual Int Calculateyearincome ( Int Year ){ If (Year < 2000 ){ Return 50000 ;} Return 10000 ;}} Class Employee: person { Public Int Yearincome { Get ; Set ;} Public Override Void Display () {console. writeline ( " Employee-{0}, {1}, {2} " , Firstname, secondname, yearincome );} Public Override Int Calculateyearincome ( Int Year ){ Return 1000 ;}} Class Program { Static Void Main ( String [] ARGs) {list <Person> mylist =New List <person> (); Person p1 = New Person (); p1.firstname = " Nelson " ; P1.secondname = " Laquest " ; Employee E1 = New Employee (); e1.firstname = " Whoa " ; E1.secondname = " Hey " ; E1.yearincome = 23 ; Mylist. Add (P1); mylist. Add (E1 ); Foreach ( VaR Item In Mylist) {item. Display (); console. writeline ( " Year income of 2004-> {0} " , Item. calculateyearincome ( 2004 );} Console. readkey ();} Static String Getstring ( String Prompt) {console. Write ( " {0}> " , Prompt ); Return Console. Readline ();}}}
Polymorphism:
Using System; Using System. Collections. Generic; Using System. LINQ; Using System. text; Namespace Leleapplication2 { Class Person { Public String Firstname { Get ; Set ;} Public String Secondname { Get ; Set ;} Public Virtual Void Display () {console. writeline ( " Person-{0}, {1} " , Firstname, secondname );}} Class Employee: person { Public Int Yearincome { Get ; Set ;} Public Override Void Display () {console. writeline ( " Employee-{0}, {1}, {2} " , Firstname, secondname, yearincome );}} Class Program { Static Void Main ( String [] ARGs) {list <Person> mylist = New List <person> (); For ( Int I = 0 ; I < 3 ; I ++ ) {Mylist. Add (getpersoninput ());} Foreach ( VaR Item In Mylist) {item. Display ();} console. readkey ();} Static Person getpersoninput (){ While ( True ) {Console. writeline ( " [1]-person \ n [2]-Employee " ); Int Choice = Int . Parse (console. Readline ()); If (Choice = 1 ) {Person = New Person (); person. firstname = Getstring ( " First name " ); Person. secondname = Getstring ( " Second name " ); Return Person ;} Else If (Choice = 2 ) {Employee = New Employee (); employee. firstname = Getstring ( " First name " ); Employee. secondname = Getstring ( " Second name " ); Console. writeline ( " Year of income> " ); Employee. yearincome = Int . Parse (console. Readline ()); Return Employee ;}}} Static String Getstring ( String Prompt) {console. Write ( " {0}> " , Prompt ); Return Console. Readline ();}}}