Tag: ambiguity

C#以下方法或属性之间的调用不明确:’System.Math.Round(double,int)’和’System.Math.Round(decimal,int)

由于以下错误,我的代码无法编译: 以下方法或属性之间的调用不明确:’System.Math.Round(double,int)’和’System.Math.Round(decimal,int) 我的代码是 Math.Round(new FileInfo(strFilePath).Length / 1024, 1) 我怎样才能解决这个问题? 谢谢

使用Action 参数重载调用不明确的方法

在使用不同的Action变体调用重载方法时,我遇到了一些意外的编译器行为。 假设我有这个类Test ,我在CallTest构造函数中创建它的实例。 public class Test { public Test(Action arg) { } public Test(Action arg) { } } public class CallTest { public CallTest() { Test t = new Test(TestDecimal); } public void TestDecimal(decimal arg) { } public void TestLong(long arg) { } } 当使用TestDecimal或TestLong作为参数调用Test构造函数时,我收到以下错误: 以下方法或属性之间的调用不明确:’ Test(System.Action) ‘和’ Test(System.Action) ‘ 我的猜测是在long和decimal之间有一些隐式转换,但有没有人有任何其他想法我可能做错了什么? 有没有解决方法?

为什么C#允许通过可选参数进行模糊函数调用?

我今天遇到了这个,我很惊讶我之前没有注意到它。 给出一个简单的C#程序,类似于以下内容: public class Program { public static void Main(string[] args) { Method(); // Called the method with no arguments. Method(“a string”); // Called the method with a string. Console.ReadLine(); } public static void Method() { Console.WriteLine(“Called the method with no arguments.”); } public static void Method(string aString = “a string”) { Console.WriteLine(“Called the method […]

使用’Microsoft.Office.Interop.Word._Document.Close’时编译时间警告

有谁知道如何解决这个警告信息? 方法’Microsoft.Office.Interop.Word._Document.Close(ref object,ref object,ref object)’和非方法’Microsoft.Office.Interop.Word.DocumentEvents2_Event.Close’之间的歧义。 使用方法组。