Im creating a program that will only greet the person if named carley and zack.
string name1 = "Carley";
string name2 = "Zack";
Console.Write("What's your name? : ");
string name = Console.ReadLine();
if (name == name1)
{
Console.WriteLine("Glad to meet you " + name + "!");
}
else if (name == name2)
{
Console.WriteLine("Glad to meet you " + name + "!");
}
else
{
Console.WriteLine("press any key to exit.");
}
Console.Read();
Here I am, hoping to simplify the code by trying to put the evaluation of the input in one statement for the "if":
if (name == name1 && name2)
{
Console.WriteLine("Glad to meet you " + name + "!");
}
else
{
Console.WriteLine("press any key to exit.");
}
Console.Read();
But it says the AND (&&) cant be applied for boolean and string. Can you please explain and help me out with this code, and also figuring out, it can accept input regardless if it has upper and lowercase etc.