C # Operation Office warning: there is ambiguity between methods and non-methods

Source: Internet
Author: User

Recently, I am working on Office development. When operating Word, I found a warning of "ambiguity:

 

The reason is simple. Let's take a look at it first:

Application inherits two interfaces, both of which have a member named "Quit:

    1. _ Quit method in Application: void Quit (ref object SaveChanges, ref object OriginalFormat, ref object RouteDocument );
    2. Quit event in ApplicationEvents4: event ApplicationEvents4_QuitEventHandler Quit;

New Application () returns an instance of the ApplicationClass class. ApplicationClass implements the above interface:

ApplicationEvents4.Quit event is implemented in a strange way (row 258). Its name is changed to ApplicationEvents4_Event. Probably because the ApplicationClass class already has a method named Quit (slice 953 rows), there is a name conflict, so avoid it (but do not know why this method is used ). Because the DocumentBeforeClose event does not have a duplicate Member, its name is consistent with that defined in the interface.

Despite such processing, ApplicationEvents4_Event.Quit is not an explicit interface implementation, so two members with the same name appear: One method and one event (not a method ). At compilation, you must determine a method. The method may have a higher priority than the event, so the compiler "will use the method group ".

The above is my bold speculation. I don't know if it is reasonable. Please give me some advice.

Note: After you press F6 to compile, this warning will disappear, and the project will appear again after being regenerated.

 

As mentioned above, members of the same name are not allowed in c # (except for method overloading). For example, the following code cannot be compiled:

 

In this case, the implementation interface must be displayed.

Related Article

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.