c# - 使用 'Microsoft.Office.Interop.Word._Document.Close' 时出现警告 CS0467

标签 c# compiler-warnings

问题(C#编译器警告信息):

warning CS0467: Ambiguity between method 'Microsoft.Office.Interop.Word._Document.close(ref object, ref object, ref object)' and non-method 'Microsoft.Office.Interop.Word.DocumentEvents2_Event.Close'. Using method group.

(部分..)解决方案: Compile time warning when using 'Microsoft.Office.Interop.Word._Document.Close'

困境: 如果我明确转换为 Microsoft.Office.Interop.Word._Document,ReSharper 会警告我“类型转换是多余的”

问题: 这个警告消息是否有真正的解决方案,而不仅仅是拼凑而成?

最佳答案

只是不要转换,C# 不需要它:

Word._Application app = new Word.Application();
Word._Document doc = app.Documents.Add(...);
doc.Close(...);    // No ambiguity
app.Quit(...);

关于c# - 使用 'Microsoft.Office.Interop.Word._Document.Close' 时出现警告 CS0467,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10480119/

相关文章:

c# - C#/MVVM : Enable/Disable Buttons based on another control's property

c# - 数据模型中没有为 TextBox Text 属性调用 Setter

android - 更新 Android Studio 3.1 后,每次构建后我都会收到这些警告

Java 编译器/eclipse 无法识别死代码

c++ - 为什么 msvc 编译器在显式调用析构函数时会发出未使用的变量

javascript - 在 MVC 中将 2D 对象数组 C# 转换为 Javascript

c# - 优化加载和搜索速度 ASP.NET C#

c# - 预测 base64 编码 byte[] 的字节大小

scala - 如何解决未使用警告的值(value)丢弃

ios - 此处使用 '!' 已弃用,将在未来版本中删除 - swift 4.2