私はまったく新しいものです。 I入力「間違った」ユーザ名とパスワードは、それが示したときに何らかの理由で私のログイン資格情報(ループのため)としての配列
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
string[] usernames = { "user1", "user2" };
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i <= usernames.Length; i++)
{
if (textBox1.Text == usernames[i] && textBox2.Text == "password")
{
Form2 frm = new Form2();
frm.Show();
this.Hide();
break;
}
else
{
textBox1.Clear();
textBox2.Clear();
textBox1.Text = "Wrong credentials!";
}
}
}
:
if (textBox1.Text == usernames[i] && textBox2.Text == "password")
An unhandled exception of type 'System.IndexOutOfRangeException' occurred in WindowsFormsApplication2.exe
があるならとにかく私はだからここに私の現在のコードだ君たちは少し私を助けることを願っこれをコード化するより良い方法です(ずっと簡単です)。あなた自身のコードを投稿するのをためらってください。私は配列を使ってログインフォームが必要です!本当にありがとう!
使用のデバッグを試してみて、あなたは 'I <= usernames.Length'を書いているので、 – mybirthname
は論理的には、とき'私は= usernames.Length'何が起こるかを歩くなぜあなたが表示されます。 – Rob