我试图为选项质量做一个CASE但我收到的操作员错误是“==”这个问题的解决方案是什么。?
这是
背后的代码 private void myComboBoxThatICreatedInXaml_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (myComboBoxThatICreatedInXaml.SelectedValue.ToString == Low)
{
QualityChoices.Add(YouTubeQuality.QualityHigh);
case
(myComboBoxThatICreatedInXaml.SelectedValue.ToString == Medium)
{
QualityChoices.Add(YouTubeQuality.QualityMedium);
}
case
(myComboBoxThatICreatedInXaml.SelectedValue.ToString == High)
{
QualityChoices.Add(YouTubeQuality.QualityHigh);
}
}
这是我的xaml代码。
<ComboBox x:Name="myComboBoxThatICreatedInXaml" SelectionChanged="myComboBoxThatICreatedInXaml_SelectionChanged" >
<ComboBoxItem Tag="LW">Low</ComboBoxItem>
<ComboBoxItem Tag="MD">Medium</ComboBoxItem>
<ComboBoxItem Tag="HG">High</ComboBoxItem>
</ComboBox>
答案 0 :(得分:3)
你有一些C#语法问题。 ()
方法需要ToString
,字符串文字周围需要引号:
if (myComboBoxThatICreatedInXaml.SelectedValue.ToString() == "Low")
如果你想使用switch语句,那就是这样的:
switch(myComboBoxThatICreatedInXaml.SelectedValue.ToString())
{
case "Low":
QualityChoices.Add(YouTubeQuality.QualityHigh);
break;
case "Medium":
QualityChoices.Add(YouTubeQuality.QualityMedium);
break;
case "High":
QualityChoices.Add(YouTubeQuality.QualityHigh);
break;
default:
break;
}