0

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>

1 Answer 1

3

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;
} 
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.