double dblSquare;
double strlbl;
double sum;
dblSquare = double.Parse(txtSquare.Text);
sum = "the square of" dblSquare "is" dblSquare* dblSquare;
strlbl = sum;
我如何让这个工作,以便我可以让标签说"(输入的数字)的平方是(输入的数字的平方)"
答案 0 :(得分:1)
您需要执行以下string concatenation:
yourlabel.Text = strResult;
然后
public void onDestroyView() {
super.onDestroyView();
Fragment fragment = (getFragmentManager().findFragmentById(R.id.map));
FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
ft.remove(fragment);
ft.commit();
}
连接是将一个字符串附加到末尾的过程 另一个字串。连接字符串文字或字符串时 常量使用+运算符,编译器创建一个 串。没有运行时连接发生。但是,字符串变量 只能在运行时连接。在这种情况下,你应该 了解各种方法的性能影响。
答案 1 :(得分:1)
使用+
进行连接。
将标签的值设置为:
strlbl.Text = "The square of " + dblSquare + " is " + (dblSquare * dblSquare);
答案 2 :(得分:1)
直接在字符串变量中赋值,如下所示
strlbl = "the square of"+ dblSquare+ "is"+ dblSquare* dblSquare;
答案 3 :(得分:0)
string strlbl = string.Format("the square of {0} is {1}.", dblSquare, dblSquare * dblSquare);