C# The call is ambiguous between the following methods or properties: 'System.Math.Round(double, int)' and 'System.Math.Round(decimal, int)

二次信任 提交于 2019-12-03 11:31:47

问题


My code won't compile due to the error below:

The call is ambiguous between the following methods or properties: 'System.Math.Round(double, int)' and 'System.Math.Round(decimal, int)

My code is

Math.Round(new FileInfo(strFilePath).Length / 1024, 1)

How can I fix this?

Thanks


回答1:


The problem is that you make an integer division (results also in an int) and a int can be implicitly converted to both double and decimal. Therefore, you need to make sure the expression results in one of those; double is probably what you want.

Math.Round(new FileInfo(strFilePath).Length / 1024.0, 1)



回答2:


Math.Round(new FileInfo(strFilePath).Length / 1024d, 1)



回答3:


Math.Round((double) (new FileInfo(strFilePath).Length / 1024), 1)


来源:https://stackoverflow.com/questions/771825/c-sharp-the-call-is-ambiguous-between-the-following-methods-or-properties-syst

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!