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)
我怎样才能解决这个问题?
谢谢
问题是你进行整数除法(结果也是int
), int
可以隐式转换为double
和decimal
。 因此,您需要确保表达式导致其中一个; double
可能是你想要的。
Math.Round(new FileInfo(strFilePath).Length / 1024.0, 1)
Math.Round(new FileInfo(strFilePath).Length / 1024d, 1)
Math.Round((double) (new FileInfo(strFilePath).Length / 1024), 1)