usingSystem;usingSystem.Collections;usingSystem.Collections.Generic;usingSystem.Linq;namespaceconsoleapplication1{classProgram { Public InterfaceIvisitor {voidVisit (Printera a); voidVisit (Printerb b); } Public Abstract classPrinter { Public Abstract voidAccept (Ivisitor visitor); Public Abstract voidPrint (); } Public classPrintera:printer { Public Override voidAccept (Ivisitor visitor) {visitor. Visit ( This); } Public Override voidPrint () {Console.WriteLine ("I am is a"); } } Public classPrinterb:printer { Public Override voidAccept (Ivisitor visitor) {visitor. Visit ( This); } Public Override voidPrint () {Console.WriteLine ("I am b"); } } Public classConcretevisitor:ivisitor { Public voidVisit (Printera a) {a.print (); } Public voidVisit (Printerb b) {b.print (); } } Static voidMain (string[] args) {Printer a=NewPrintera (); Printer b=NewPrinterb (); A.accept (Newconcretevisitor ()); B.accept (Newconcretevisitor ()); } }}
Visitor Mode C #