C #-Interface _ Explicit interface implementation

Source: Internet
Author: User

1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 6 /*----------------------------------------------------------------------------7 * Explicitly implement the interface:8 * 1. A class inherits more than two interfaces9 * 2. Methods with the same name in the interfaceTen * 3. Display the implementation in the class through the "interface. Method ()" Format One * 4. To pass an instantiated object of a class to a different interface object, call the A * is the different interface under the respective methods - * 5. You cannot use any modifiers before explicitly implementing an interface method in a class - * 6. Show that the implemented members are private by default, i.e. they cannot be instantiated through a class the * objects are called directly outside the class, and the correct way to access them is through the class pair - * Like explicit conversion to the corresponding interface, through the interface to access the method - -----------------------------------------------------------------------------*/ - namespaceInterface _ Explicit interface implementation + { -     //defining interfaces: Ichinesegreeting +     Interfaceichinesegreeting A     { at         voidSayHello (); -     } -  -     //defining interfaces: Iamericangreeting -     Interfaceiamericangreeting -     { in         voidSayHello (); -     } to  +     //Implementation Interface: Speaker class -      Public classspeaker:ichinesegreeting, iamericangreeting the     { *         //Interface: ichinesegreeting Display implementation $         voidIchinesegreeting.sayhello ()Panax Notoginseng         { -Console.WriteLine ("Hi there!"); the         } +  A         //Interface: iamericangreeting Display implementation the         voidIamericangreeting.sayhello () +         { -Console.WriteLine ("hello!"); $         } $     } -  -     class Program the     { -         Static voidMain (string[] args)Wuyi         { theSpeaker Speaker =NewSpeaker (); -              WuIchinesegreeting ichineseg =(ichinesegreeting) speaker; -Ichineseg.sayhello ();//output "Hello" " About  $Iamericangreeting Iamericang =(iamericangreeting) speaker; -Iamericang.sayhello ();//output "" Hello "" -  - console.readline (); A         } +     } the}

C #-Interface _ Explicit interface implementation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.