I can't mark multiple strings in my statement if, i want to make talking console app and when is typed / chat is over

44 Views Asked by At
using System;

namespace Let_sTalk
{
    class Program
    {
        static void Main(string[] args)
        {         
            Console.Write("<-:");
            string q = Console.ReadLine();
            string w = Console.ReadLine();
            string e = Console.ReadLine();

            if (q, w, e == "/")
            {
                Console.WriteLine("over");
            }
        }
    }
}
1

There are 1 best solutions below

1
On

You cannot use the comma (,) symbol to separate variables in an if statement. That's invalid C# syntax.

Also, in C# string comparison is done with the Equals function. The == will still work in most cases, but there are some additional error handlings with the Equals function.

If you want to check if at least one of the q, w, e variables is equal to /, then use the following code:

if (q.Equals("/") || w.Equals("/") || e.Equals("/"))
{
    Console.WriteLine("over");
}

If you wish to check if all q, w, e variables are equal to /, then you have to replace the || (or operator) with && (and operator) like so:

if (q.Equals("/") && w.Equals("/") && e.Equals("/"))
{
    Console.WriteLine("over");
}