lundi 18 mai 2015

Implementing strings and the OR function (||) in an if statement

I am currently trying to make an if statement to validate a string. This is currently what I have.

        Console.Write("Please enter your phone number: ");
        string input = Console.ReadLine();

        if (input.Length < 9)
        {
            Console.WriteLine("Phone number is not valid, please try again.");
        }

        string everythingButThePlus = input.Substring(1);
        string justThePlus = input.Substring(0, 1);

        if (justThePlus = "+" || "1" || "2" || "3" || "4" || "5" || "6" || "7" || "8" || "9" || "0") ;
        {

        }
        Console.ReadLine();

The portion, "justThePlus = "+" ||" is currently got a red underline with the description being,

"Operator '||' cannot be applied to operands of type 'string' and 'string'.

If I can't use OR statements, what is an alternative that works with strings?

Aucun commentaire:

Enregistrer un commentaire