Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#Can';无法获取MessageBox以显示变量_C#_Variables_Messagebox - Fatal编程技术网

C#Can';无法获取MessageBox以显示变量

C#Can';无法获取MessageBox以显示变量,c#,variables,messagebox,C#,Variables,Messagebox,它很好地显示了我的结果,但我想添加以下对话框“一个长为l、宽为w、高为h的框,其体积为x”(l、w、h和x是用户的输入) double heightLabelBox; double lengthLabelBox; double widthLabelBox; double result; heightLabelBox = double.Parse(heightTextBox.Text); lengthLabelBox = double.Parse(len

它很好地显示了我的结果,但我想添加以下对话框“一个长为l、宽为w、高为h的框,其体积为x”(l、w、h和x是用户的输入)

 double heightLabelBox;
 double lengthLabelBox;
 double widthLabelBox;
 double result;

        heightLabelBox = double.Parse(heightTextBox.Text);

        lengthLabelBox = double.Parse(lengthTextBox.Text);

        widthLabelBox = double.Parse(lengthTextBox.Text);

        result = heightLabelBox * lengthLabelBox * widthLabelBox;

 MessageBox.Show(result.ToString());
试试这个:

 MessageBox.Show(string.format("A box with length {0}, width {1} and height {2} has a volume of {3}", lengthLabelBox, widthLabelBox, heightLabelBox, result));
但是,尝试以这种方式对其进行格式化没有意义,因为您已经有了文本框值,因此只需使用string.Join或“+”运算符将其连接在一起,或者使用string.format about,只需将文本框值替换为文本框值,并将其替换为解析值

您还可以使用StringBuilder:

var sb = new StringBuilder(50); // give it an initial value/capacity.
sb.AppendFormat("A box with length {0}, width {1} and height {2} has a volume of {3}", lengthTextBox.Text, widthTextBox.Text, heightTextBox.Text, result);

MessageBox.Show(sb.ToString());

messagebox.show的输出是什么?请先尝试将双变量转换为字符串/或,然后使用string.Format创建新变量,或在messagebox声明本身中创建新变量。您可能还希望将双值缩短到小数位数以下。

为什么不将字符串与结果合并在一起。ToString()?您尝试过什么?c语言中的google字符串连接?请不要忘记添加检查,以查看文本框中的值是否实际上是有效的双精度值。