我尝试登录时出现此错误.
索引(从零开始)必须大于或等于零且小于参数列表的大小.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//string name = textBox1.Text;
string.Format ("{0} {1}", "Best", "Regards");
if (textBox1.Text == "Ryan" && textBox2.Text == "password")
{
MessageBox.Show(string.Format("Welcome {1}" ));
}
}
}
Run Code Online (Sandbox Code Playgroud)
此行中出现错误:
MessageBox.Show(string.Format("Welcome {1}" ));
Run Code Online (Sandbox Code Playgroud)
因为你已经使用了占位符{1}但是没有为string.Format函数提供参数.除此之外,您还没有开始使用索引0.
你必须提供一个参数并从索引0开始:
MessageBox.Show(string.Format("Welcome {0}", textBox1.Text));
Run Code Online (Sandbox Code Playgroud)