我正在使用 VS2010 构建一个 Windows 窗体应用程序。我想读取用户从下拉列表中选择的值并基于该值ComboBox
生成。patientNo
但是当我运行应用程序时,我得到一个NullReferenceException
.
这是我的代码:
private void button1_Click(object sender, EventArgs e)
{
string patientNumber;
string gender = comboBox2.SelectedValue.ToString();
if (gender != null)
{
if (gender == "Female")
{
var generator = new PatientNumberGenerator();
patientNumber = generator.GeneratePatientNumber(Gender.Female);
const string message = "patientNumber";
const string caption = "Testing PatientNumber class";
var result = MessageBox.Show(message, caption,
MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
}
else if (gender == "Male")
{
var generator = new PatientNumberGenerator();
patientNumber = generator.GeneratePatientNumber(Gender.Male);
const string message = "patientNumber";
const string caption = "Testing PatientNumber class";
var result = MessageBox.Show(message, caption,
MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
}
}
}