Error when comparing string

Asked

Viewed 92 times

5

I’m trying to finish my last few pieces of code and I need to check the value of a string, but I can’t find any example on how to handle. I tried this code, but error appears:

Error 1 Cannot implicitly Convert type 'string' to 'bool'
Testform.Cs 956 17

This is my variable:

public string malcoins = "0";

And this is the code:

if (malcoins = "100000")
{

}

I need to compare if the variable is = 100000, otherwise I disable the button2

1 answer

5


Exchange the = for ==:

if (malcoins == "100000")
{

}

Or use Equals:

if (malcoins.Equals("100000") == true){

}

Or else the Compare, which returns zero if equal:

if (malcoins.Compare(malcoins, "100000") == 0)
{

}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.