usingSystem;namespaceClassLibrary2 {InterfaceIemploy//Interface{ voidSpeak ();//Method}classHello:iemploy//Hello class Implementation Interface{ Public voidSpeak ()//Implementation Method{Console.WriteLine ("Hello: Friend"); }}classSorry:iemploy//Sorry class implementation interface{ Public voidSpeak ()//Implementation Method{Console.WriteLine ("Sorry: Friend"); }} } //Implement//Call directlyIemploy Ie =NewHello (); Ie.speak (); //calling the interface implemented by the Hello classIemploy Ie=NewSorry (); Ie.speak ();//The reflection call remembers the reflection of the spatial reference using the System.Reflection;Assembly ASM= Assembly.Load ("ClassLibrary2");//reflect the spaceType Type= Asm.gettype ("Classlibrary2.hello");//class reflected out of spaceObjectAssclas = Activator.CreateInstance (type);//Dynamic Strength Reflection returns the specified class under the specified spaceIemploy Ie= (Iemploy) Assclas;////Convert to interface type//commonly used in these kinds of methods
How to use C # interfaces