I know there is a question similar to this one but the naswers there didnt help me that much it was compicated so i asked this new one
i was trying to convert char into upper case by .ToUpper method
but it is give me this issue
Operator ‘==’ cannot be applied to operands of type ‘char’ and ‘string’
here is the code
char UserChoice = Convert.ToChar(Console.ReadLine());
char upperCaseChoice = Char.ToUpperInvariant(UserChoice);
if (UserChoice == "Y" || upperCaseChoice == "YES")
{
TotalCoffeeCost = askForCoffee(TotalCoffeeCost); //Note here that we did not set invalidChoice to false, meaning it will loop again
}
else if (upperCaseChoice == "N" || upperCaseChoice == "NO")
{
invalidChoice = false;
}
else
{
Console.WriteLine("");
Console.WriteLine(" Please enter a valid choice");
}
upperCaseChoice == "YES"is impossible (a single character cannot match 3 characters). You seem to wantUserChoice == 'Y'. Also note that common convention dictates that local variables should be camelCase not PascalCase.yesorno, usingstringis reasonable here.Console.ReadLine(), this returns astring. You're then callingConvert.ToCharto get the first character from that string. So you have multiple pieces of data in memory: the length of the string, its characters, and this new single character. Now, with .NET's garbage collection, it will still be a while before the data from the original string gets expunged. Therefore, you're actually using more memory in the time until that gets GC'd.