且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法将类型'double'隐式转换为'string'

更新时间:2023-02-18 21:08:44

您可能只是缺少.ToString():

You're probably just missing a .ToString():

lblDiameter.Text = (double.Parse(radius.Text) * double.Parse(radius.Text)).ToString();

这会更清楚,您可以通过将数字存储在局部变量中来避免对字符串进行两次解析:

It'd be clearer and you'd avoid parsing the string twice by storing the number in a local variable:

var value = double.Parse(radius.Text);
lblDiameter.Text = (value * value).ToString();

现在,直径真的等于半径的平方吗?;)

Now, is a diameter really equal to the square of the radius? ;)