Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I validate these variables without an if else statement?

I’m very new to c# so please excuse my lack of knowledge. I’m just trying to check the following:

  • "CardNumberLength" = 16
  • "CardPINLength" = 3
  • "CardNameHasSpace" 0
    I don’t want to use an if else statement, is there another way?

The code:

public bool Validate()

        {

            CardNumberLength = Convert.ToString(GetCardNumber()).Length;

            CardPINLength = Convert.ToString(GetCardPIN()).Length;

            CardNameHasSpace = GetCardName().IndexOf(" ");

        }

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You could just return the boolean result:

return CardNumberLength == 16 && CardPINLength == 3 && CardNameHasSpace >= 0;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading