为什么没有Convert.toFloat()方法?


86

为什么是不存在的方法Convert.ToFloat(),C#有ToDouble()ToDecimal()......
我想转换为浮动,该方法可以用吗?(浮动)变量?

Answers:


154

有-但这叫Convert.ToSingle()float是该System.Single类型的C#别名。

“单”是BCL中的浮点名称。“ float”是C#提供的别名。有一个Convert.ToSingle()方法,就像有Convert.ToInt32()而不是Convert.ToInt()一样。

参见此线程Convert类

(顺便说一句-我也不知道,所以我今天学到了一些新东西:))

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.