如何使用标签c#

How to use labels c#

double dblSquare;
double strlbl;
double sum;

dblSquare = double.Parse(txtSquare.Text);

sum = "the square of" dblSquare "is" dblSquare* dblSquare;

strlbl = sum;

我如何让它工作,以便我可以让标签说 "the square of (what ever number is entered) is (the square of what ever number is entered)"

您需要像下面那样string concatenation

string strResult = "the square of " + dblSquare + " is " + dblSquare * dblSquare;

然后

yourlabel.Text = strResult;

Concatenation is the process of appending one string to the end of another string. When you concatenate string literals or string constants by using the + operator, the compiler creates a single string. No run time concatenation occurs. However, string variables can be concatenated only at run time. In this case, you should understand the performance implications of the various approaches.

使用 + 进行串联。

设置标签的值为:

strlbl.Text = "The square of " + dblSquare + " is " + (dblSquare * dblSquare);

像这样直接给字符串变量赋值

strlbl = "the square of"+ dblSquare+ "is"+ dblSquare* dblSquare;
string strlbl = string.Format("the square of {0} is {1}.", dblSquare, dblSquare * dblSquare);