Error comparing string [closed]

5

I'm trying to finish my last parts of the code, and I need to check the value of string , but I can not find any examples of how to handle it. I tried this code but the error appears:

  

Error 1 Can not implicitly convert type 'string' to 'bool'
  TestForm.cs 956 17

This is my variable:

public string malcoins = "0";

And here's the code:

if (malcoins = "100000")
{

}

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

    
asked by anonymous 22.07.2017 / 00:22

1 answer

5

Change = by == :

if (malcoins == "100000")
{

}

Or use Equals :

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

}

Or the Compare , which returns zero if it is the same:

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

}
    
22.07.2017 / 00:33