この特定のエラーはかなりの回数解決されているようですが、私のコード スニペットには、「割り当てられていない」エラーが発生しないという点で違いがあります。
このコードは、私が学校で行っているプロジェクトからのものです。私はここで見つけたいと思っている助けを求めることが許されています。商用目的ではないため、変数などをマスクすることは気にしません。
これはコンパイル時のエラーです:「割り当てられていないローカル変数 'dateStartedActual' の使用」
switch (userType)
{
case "Doctor":
string qualification = Microsoft.VisualBasic.Interaction.InputBox("What is the highest qualification this person has", "Qualification", "", -1, -1);
while (dateStarted == "")
{
try
{
dateStarted = Microsoft.VisualBasic.Interaction.InputBox("On which date did this person start", "Date Started", "", -1, -1);
int day = Convert.ToInt32(Regex.Match(dateStarted, @"\d{2}").Value);
dateStarted.Remove(0,3);
int month = Convert.ToInt32(Regex.Match(dateStarted, @"\d{2}").Value);
dateStarted.Remove(0,3);
int year = Convert.ToInt32(Regex.Match(dateStarted, @"\d{4}").Value);
dateStartedActual = new DateTime(day, month, year);
}
catch (Exception ex)
{
MessageBox.Show("The date entered is not valid");
dateStarted = "";
}
}
string field = Microsoft.VisualBasic.Interaction.InputBox("In which field does this person practice", "Field", "", -1, -1);
CreateDoctor(qualification, dateStartedActual, field);
break;