如何将文本+字符串放入文本框中 [英] How to put text + string into textbox

查看:147
本文介绍了如何将文本+字符串放入文本框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的文本框能够写出文字+字符串



I want my textbox to write text + string

string a = "Morning"
textBox2.Text = ("Good {0}", a);





为早安的文本框输出但是它不起作用



我尝试了什么:



但是如何在控制台应用程序上运行





for an textbox output of "Good Morning" however it doesn't work

What I have tried:

but how come this on console application works

Console.WriteLine("temperature on Thursday is {0} degrees ", temperature);

推荐答案

叹息......

Sigh...
string a = "Morning";
textbox2.Text = string.Format("Good {0}", a);



它在WriteLine中工作的原因是因为你正在使用WriteLine的重载,专门为你调用string.Format()。



这不是字符串处理和分配的工作方式。



但是,在较新版本的C#中,你可以这样做:


The reason it works in WriteLine is because you're using an overload of WriteLine that specifically handles the string.Format() call for you.

That's not how string handling and assignments work though.

However, in newer versions of C#, you can do this:

string a = "Morning";
textbox2.Text =


Good {a}< /跨度>;
"Good {a}";


这篇关于如何将文本+字符串放入文本框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆