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(" ");

        }

>Solution :

You could just return the boolean result:

return CardNumberLength == 16 && CardPINLength == 3 && CardNameHasSpace >= 0;

Leave a Reply