Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

125
Visualizações
Bool method keeps returning false

So this code checks to make sure the user has entered a proper math operator in my calculator, but no matter what I seem to do the code ALWAYS gives me false and it's driving me nuts.

if (IsOperator(txtOperator.ToString(), "Operator")




        public bool IsOperator(string textBox, string name)
        {
            switch (textBox)
            {
                case "*":
                    return true;
                case "x":
                    return true;
                case "/":
                    return true;
                case "+":
                    return true;
                case "-":
                    return true;
            }
                MessageBox.Show(name + " must be a valid math operator.", "Entry Error");
                return false;
        }
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

I think you need txtOperator.Text instead of txtOperator.ToString() in the call to IsOperator, assuming txtOperator is a TextBox.

Have you already debugged the app and inspected the value?

over 4 years ago · Santiago Trujillo Relatório

0

Probably you just need to pass in the the Text property of that textbox...

   if (IsOperator(txtOperator.Text, "Operator")) { ...

The method itself could be optimized to sth like:

    public bool IsOperator(string textEntered, string name)
    {
        switch (textEntered?.Trim())
        {
            case "*":
            case "x":
            case "/":
            case "+":
            case "-":
                return true;

            default:
                MessageBox.Show(name + " must be a valid math operator", "Entry Error");
                return false;

        }
    }
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda