Trying to learn c# and dont understand why i cant compare string.

if (answere == 'j' || answere == 'J')
            {
                again = true;
            }
            else
                again = false;

How do I do to make this happen in c#?

If the type of answere is string then you must compare against a string.
'j' and 'J' are of type char. To make them string, use "j" and "J".

You cad do it like:

string answare = "j";
bool again = (answare == "j" || answare == "J") ? true : false;

about your issue: as ddanbe explained, (') is a type char, and I presume that variable answare is a type string ("). So these two will no go along. Or use one or the other.

This is a short version where you can choose between true of false.
Mitja

Edited 5 Years Ago by Mitja Bonca: n/a

You cad do it like:

string answare = "j";
bool again = (answare == "j" || answare == "J") ? true : false;

No need for the ? : part, it will return true/false anyway. You can also just do:

bool again = answare.ToUpper() == "J";

That one i didnt know before. Youre all wonderfull at this forum!

If you would mark this thread as solved, who knows, what wonderfull and miraculous things we can do for you!

:) Indeed. Maybe we can find out some thing which even Microsoft doesn`t know, and it will be implemented in VS 4.5
:)

This question has already been answered. Start a new discussion instead.