2调试警告 [英] 2 Warning on Debugging

查看:67
本文介绍了2调试警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下字样的警告:
退出关闭在最后几行.

这是警告:
方法"Microsoft.Office.Interop.Word._Application.Quit(引用对象,引用对象,引用对象)"和非方法"Microsoft.Office.Interop.Word.ApplicationEvents4_Event.Quit"之间的歧义.使用方法组.



这是代码:

The warning under the words:
Quit , Close in the last lines .

This is the warning:
Ambiguity between method ''Microsoft.Office.Interop.Word._Application.Quit(ref object, ref object, ref object)'' and non-method ''Microsoft.Office.Interop.Word.ApplicationEvents4_Event.Quit''. Using method group.



This is the code:

private void button1_Click_1(object sender, EventArgs e)
        {
            Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.ApplicationClass();
            object nullobj = System.Reflection.Missing.Value;
            object file = @"C:\1.doc";

            Microsoft.Office.Interop.Word.Document doc = app.Documents.Open(
            ref file, ref nullobj, ref nullobj,
            ref nullobj, ref nullobj, ref nullobj,
            ref nullobj, ref nullobj, ref nullobj,
            ref nullobj, ref nullobj, ref nullobj,
            ref nullobj, ref nullobj, ref nullobj, ref nullobj);
            doc.ActiveWindow.Selection.WholeStory();
            doc.ActiveWindow.Selection.Copy();
            IDataObject data = Clipboard.GetDataObject();
            string text = data.GetData(DataFormats.Text).ToString();
            MessageBox.Show(text);
            doc.Close(ref nullobj, ref nullobj, ref nullobj);
            app.Quit(ref nullobj, ref nullobj, ref nullobj);

            textBox1.Text = text;
        }

推荐答案

在C#中,方法名称不能与事件名称冲突. MSIL允许这样做.生成的COM包装器似乎具有相同名称的事件和方法. C#编译器可以使用带有这种名称冲突的程序集,但仍会发出警告.在这种情况下,警告是肤浅且无用的,因为您无法像在另一个对象上那样直接调用事件,因此完全可以忽略.如果警告使您感到烦恼,则可以通过强制转换来解决它.
In C# a method name cannot clash with an event name. MSIL permits this though. The COM wrapper that''s been generated seems to have an event and a method both with the same name. The C# compiler can consume assemblies with name-clashes of this nature, but it will still throw a warning. In this case the warning is superficial and useless since you cannot invoke an event directly like that on a different object, so it''s completely safe to ignore. You may be able to get around it by using some casting if the warning is that annoying to you.


警告表示警告内容.含糊不清的意思是我无法确定要使用哪一种".它说您正在调用退出",并且有两个退出"对象.
The warning means what it says. Ambiguity means ''I can''t work out which one of these to use''. It''s says you''re calling ''quit'' and there''s two ''quit'' objects.


Thx Guys :)得到了一个答案:PPP
Thx Guys :) Got an answer :PPP


这篇关于2调试警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆