C # display interface implementation

Source: Internet
Author: User

Display Interface implementation

If a class inherits multiple interfaces and interfaces have methods or attributes of the same name, you must use the display interface to avoid errors!

Example:

1 class Program
2 {
3 static void Main (string [] args)
4 {
5 MyClass a = new MyClass ();
6 a. show ();
7}
8}
9
10 class MyClass: Interface1, Interface2
11 {
12 public void show ()
13 {
14 Console. Write ("implementation interface ");
15}
16}
17
18 interface Interface1
19 {
20 void show ();
21}
22
23 interface Interface2
24 {
25 void show ();
26}

This should be changed:

Class Program
{
Static void Main (string [] args)
{
MyClass a = new MyClass ();
Interface1 B =;
B. show ();
}
}

Class MyClass: Interface1, Interface2
{

Void Interface1.show ()
{
Console. Write ("implementation interface 1 ");
}

Void Interface2.show ()
{
Console. Write ("implementation interface 2 ");
}
}

Actually, the location remains unchanged!

Note: display interface implementation. You cannot use class objects to call methods!

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.