The implementation of the C # extension method can be used to implement multi-class inheritance by defining an interface method.
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceconsoleapplication12{//Defining Interfaces Public Interfaceientity {stringID {Set;Get; } stringName {Set;Get; } } //implementing an extension method Public Static classIentityextentmethod { Public Static stringGetName ( Thisientity obj) { returnObj.id +":"+obj. Name; } } //implementing an Interface class Public classdemoentity:ientity { Public stringID {Set;Get; } Public stringName {Set;Get; } } classProgram {Static voidMain (string[] args) { //define an object and assign a valueDemoentity de =Newdemoentity (); De.id="001"; De. Name="Test"; //using extension methods stringRLT =De.getname (); Console.WriteLine (RLT); Console.read (); } }}
C # extension method implementation