class Myclass
{
static string[] user_Name = { "admin", "user1", "user2" };
static string[] user_Password ={ "admin", "123", "789" };
public static void Check_Method(string u_name, string u_password)
{
for (int i = 0; i < user_Name.Length; i++)
{
if (u_name == user_Name[i] && u_password == user_Password[i])
{
MessageBox.Show("login successful");
break;
}
else
{
if (i == (user_Name.Length - 1))
MessageBox.Show("Badshow");
}
}
}
public static void add_user(string name, string password)
{
i=user_Name.Length;
user_Name[i]=name;
user_Password[i]=password;
//here i want to add another user but im unable to find the way
}
}
但它給出了一個錯誤,它在數組的邊界之外。將字符串添加到字符串數組
什麼可能是最方便的方式來執行此操作?
數組超出界限錯誤的原因是您正在使用用戶名的長度作爲您的user_Name數組的索引。這並不是真正的問題,但我認爲你應該知道。 – Odrade 2013-03-05 20:11:23