在消息框 C# 中显示字符串数据
Show String Data in Message Box C#
我似乎已经失去了所有基本的编码知识,但如果我想要 MessageBox
在 C# 中显示 3 个字符串输入,我将如何处理?
string city;
string zip;
string state;
city = txtCity.Text;
zip = txtZipCode.Text;
state = txtState.Text;
MessageBox.Show("City,State,Zip:");
试试这个:
MessageBox.Show(String.Format("{0}, {1}, {2}:", city, zip, state));
用变量 city 替换 {0}
,用变量 zip 替换 {1}
,用 state 替换 {3}
。
String.Format
converts the value of objects to strings based on the formats specified and inserts them into another string.
如果您是新手,请阅读getting started with the String.Format
method
C# 6 中的新内容是:
MessageBox.Show($"{city}, {zip}, {state}");
@Lucas Trzesniewski 评论
另一个意见是使用这个:
MessageBox.Show(city + ", " + zip + ", " + state);
一起过去。
我似乎已经失去了所有基本的编码知识,但如果我想要 MessageBox
在 C# 中显示 3 个字符串输入,我将如何处理?
string city;
string zip;
string state;
city = txtCity.Text;
zip = txtZipCode.Text;
state = txtState.Text;
MessageBox.Show("City,State,Zip:");
试试这个:
MessageBox.Show(String.Format("{0}, {1}, {2}:", city, zip, state));
用变量 city 替换 {0}
,用变量 zip 替换 {1}
,用 state 替换 {3}
。
String.Format
converts the value of objects to strings based on the formats specified and inserts them into another string.
如果您是新手,请阅读getting started with the String.Format
method
C# 6 中的新内容是:
MessageBox.Show($"{city}, {zip}, {state}");
@Lucas Trzesniewski 评论
另一个意见是使用这个:
MessageBox.Show(city + ", " + zip + ", " + state);
一起过去。