c# 警告怎样修改

来源:百度知道 编辑:UC知道 时间:2024/07/03 01:16:20
出现这样的警告,要怎样修改呢?

警告1
方法“Microsoft.Office.Interop.Word._Document.Close(ref object, ref object, ref object)”和非方法“Microsoft.Office.Interop.Word.DocumentEvents2_Event.Close”之间存在二义性。将使用方法组。
Word.Document doc = null;
if (doc != null)
{
doc.Close(ref missing, ref missing, ref missing);//警告行
doc = null;
}

因为编译器不知道close这个方法到底是Microsoft.Office.Interop.Word._Document
还是Microsoft.Office.Interop.Word.DocumentEvents2_Event的方法

解决方法:调用时详细指明你是要具体调用那个对象,如:
Microsoft.Office.Interop.Word.DocumentEvents2_Event.Close()