由于以下错误,我的代码无法编译:
以下方法或属性之间的调用不明确:'System.Math.Round(double, int)' 和 'System.Math.Round(decimal, int)
我的代码是
Math.Round(new FileInfo(strFilePath).Length / 1024, 1)
我怎样才能解决这个问题?
谢谢
Math.Round(new FileInfo(strFilePath).Length / 1024d, 1)
问题是您进行整数除法(也导致 an int
)并且 aint
可以隐式转换为double
and decimal
。因此,您需要确保表达式产生其中之一;double
可能是你想要的。
Math.Round(new FileInfo(strFilePath).Length / 1024.0, 1)
Math.Round((double) (new FileInfo(strFilePath).Length / 1024), 1)