//我必須創建一個程序,確定名稱是否以正確的格式寫入,然後一旦它認爲正確,它會將名字和姓氏。C#。我不斷收到一個錯誤,指出我有「使用未分配的本地變量'全名'」
public partial class nameFormatForm : Form
{
public nameFormatForm()
{
InitializeComponent();
}
private bool IsValidFullName(string str)
{
bool letters;
bool character;
bool fullname;
foreach (char ch in str)
{
if (char.IsLetter(ch) && str.Contains(", "))
{
fullname = true;
}
else
{
MessageBox.Show("Full name is not in the proper format");
}
}
return fullname;
}
private void exitButton_Click(object sender, EventArgs e)
{
this.Close();
}
private void clearScreenButton_Click(object sender, EventArgs e)
{
exitButton.Focus();
displayFirstLabel.Text = "";
displayLastLabel.Text = "";
nameTextBox.Text = "";
}
private void formatNameButton_Click(object sender, EventArgs e)
{
clearScreenButton.Focus();
}
}
給全名分配一個初始值即:'bool fullname = false;' – Nkosi