C#中调用以下方法或属性之间暧昧:“System.Math.Round(双,INT)'和'System.Math.Round(十进制,INT) [英] C# The call is ambiguous between the following methods or properties: 'System.Math.Round(double, int)' and 'System.Math.Round(decimal, int)

查看:379
本文介绍了C#中调用以下方法或属性之间暧昧:“System.Math.Round(双,INT)'和'System.Math.Round(十进制,INT)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码不会编译由于以下错误:

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

调用以下方法或属性之间暧昧:System.Math.Round(双, INT)'和'System.Math.Round(十进制,INT)

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

我的代码是

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

我该如何解决这个问题?

How can I fix this?

感谢

推荐答案

的问题是,你让一个整数除法(结果亦在 INT )和 INT 可隐式转换为两个双击小数。因此,您需要确保表达式的结果其中之一; 双击大概是whal你想要的。

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 whal you want.

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

这篇关于C#中调用以下方法或属性之间暧昧:“System.Math.Round(双,INT)'和'System.Math.Round(十进制,INT)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆