【发布时间】:2017-04-23 16:31:06
【问题描述】:
//我必须创建一个程序来确定姓名是否以正确的格式写入,然后一旦它认为它正确,它将名字和姓氏分开。
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;
标签: c# visual-studio-2015