更新时间:2023-02-21 09:22:59
你可以使用string.Split()。
http://msdn.microsoft.com/en-us/library/system .string.split.aspx [ ^ ]
祝你好运!
如果您想要添加 InputBox 到数组,然后代替foreach
循环,你可以使用代替
loop。for ( int i = 0 ; i < Names.Length; i ++)
{
string prompt = Interaction.InputBox( 请输入一个string, 输入字符串);
姓名[i] =提示;
// 此处循环中的其他代码
}
private void btnButton_Click(object sender, EventArgs e)
{
int array;
string value = Interaction.InputBox("Enter array size", "Array Size");
if (int.TryParse(value, out array))
{
string[] Names = new string[array];
txtOutput.Text = "Unsorted array: \r\n";
foreach (string name in Names)
{
string prompt = Interaction.InputBox("Please enter a string" , "Enter Strings");
if (prompt == "")
{
txtOutput.Text += names +"\t";
}
}
You can use string.Split() for that.
http://msdn.microsoft.com/en-us/library/system.string.split.aspx[^]
Good luck!
If you want to add the values from theInputBox
to the array, then instead of aforeach
loop, you can use afor
loop.for (int i = 0; i < Names.Length; i++) { string prompt = Interaction.InputBox("Please enter a string" , "Enter Strings"); Names[i] = prompt; // your other code in the loop here }