【发布时间】:2017-03-06 19:23:04
【问题描述】:
所以我正在学校做关于音乐学校的课程,我想做的一件事是能够从 3 个输入的值创建一个学费代码(由 6 个字符组成)。 所以 cbInstrument 是一个组合框,cbLevel 也是一个组合框,而 rb10Lessons/rb20Lesoons 是单选按钮。当代码运行时,我希望能够在我选择这些值时从这些值创建一个学费代码,以便学费代码将显示在与我选择信息相同形式的标签中。
例如;如果在仪器的运行表格中单击“大提琴”,则 TuitionCode 显示为 CEL。之后,如果我点击 Level 为“Grade 1”,TuitionCode 就会显示为 CELB。然后如果我选择 10 节课,那么 TuitionCode = CELB10。
下面是代码示例:
private void Tuition_Click(object sender, EventArgs e)
{
string code = "";
string codePart1 = code.Substring(0, 3);
string codePart2 = code.Substring(3, 1);
string codePart3 = code.Substring(4, 2);
if (cbInstrument.Text == "Cello")
{
codePart1 = "CEL";
}
else if (cbInstrument.Text == "Clarinet")
{
codePart1 = "CLA";
}
else if (cbInstrument.Text == "Double Bass")
{
codePart1 = "DBA";
}
if ((cbLevel.Text == "None") || (cbLevel.Text == "Grade 1") || (cbLevel.Text == "Grade 2"))
{
codePart2 = "B";
}
else if ((cbLevel.Text == "Grade 3") || (cbLevel.Text == "Grade 4") || (cbLevel.Text == "Grade 5"))
{
codePart2 = "I";
}
if (rb10Lessons.Checked)
{
codePart3 = "10";
}
else if (rb20Lessons.Checked)
{
codePart3 = "20";
}
lblTuitionCode.Text = code;
}
【问题讨论】:
-
您是否尝试连接那些
codePart变量?另请注意:""上的子字符串不好。
标签: c# visual-studio substring