Reputation: 35
Im trying to do a CASE for the option quality but Im receiving a operator error of "==" what is the solution for this problem.?
This is the code behind
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);
}
}
And this is my xaml code.
<ComboBox x:Name="myComboBoxThatICreatedInXaml" SelectionChanged="myComboBoxThatICreatedInXaml_SelectionChanged" >
<ComboBoxItem Tag="LW">Low</ComboBoxItem>
<ComboBoxItem Tag="MD">Medium</ComboBoxItem>
<ComboBoxItem Tag="HG">High</ComboBoxItem>
</ComboBox>
Upvotes: 0
Views: 213
Reputation: 102723
You've got some C# syntax problems going there. You need ()
for the ToString
method, and quote-marks around the string literals:
if (myComboBoxThatICreatedInXaml.SelectedValue.ToString() == "Low")
If you wanted to use a switch statement, then it's like this:
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;
}
Upvotes: 3