-5

I have a trivial problem, but I can't solve it somehow. I have an example of code in VB

If(grid(x,y).Used = True)Then
   grid(x,y).Used = False
   ....
End If  

which look in c# like this

 if(grid[x,y]."" == false)
    {
       grid[x,y]."" = true;
    }

I can't find a substitute for "Used". I know that it's kinda stupid, but I just can't figure it out. Thanks for any advice or help.

Hero981
  • 3
  • 3
  • 2
    what is the data type of `grid` exactly? – ADyson Dec 04 '18 at 10:02
  • What is the type of grid? Given your exaple, I'd expect that the type of object should have a property called 'Used' which is a boolean. – Jay Dec 04 '18 at 10:02
  • Well, it's just a Panel[,], two-dimensional array, I just wanted to paint a grid in Windows Form (which is working) and I want to change color of one cell by pressing button. I'm trying to program a Connect 4 – Hero981 Dec 04 '18 at 10:03
  • What is `(grid[x,y].""`? – Tim Schmelter Dec 04 '18 at 10:03
  • 2
    not an answer, but it would be the next issue you'd run in to. in C# the comparator is == and not =. but like Jay said, it should have a property that is a bool. You could also just say !grid[x,y] instead of checking If(false) – Dennis Vanhout Dec 04 '18 at 10:05
  • 1
    `Used` isn't a property on a WinForms `Panel`, nor a keyword in VB.NET as far as I know. Inspect the original code and see where the `Used` property comes from. – CodeCaster Dec 04 '18 at 10:05
  • 1
    C#'s equivalent of `=` (for equality checks) is not `=` but `==`. – mjwills Dec 04 '18 at 10:13
  • 3
    The C# code is nonsense. Could happen if you used a decompiler to recover source code from an obfuscated assembly. A standard trick that an obfuscator uses is to replace characters in an identifier with unprintable control codes or characters that guarantee a compile error. Like double-quotes. Obfuscated assemblies advertise "don't steal this code". And enforce it. – Hans Passant Dec 04 '18 at 10:16
  • 1
    Your edit is a completely different problem. Why did you change `=` to `==`? You should mark @cmos as correct and then create a new question. – mjwills Dec 04 '18 at 10:28
  • Possible duplicate of [Decompile protected C#](https://stackoverflow.com/questions/40567547/decompile-protected-c-sharp) – mjwills Dec 04 '18 at 12:51

1 Answers1

3

I think you need to access your array correctly. Like this:

if(grid[x][y].Used == false)
{
    //Do something
}

Please also note that the correct syntax in C# to check for equality requires you to use the '==' operator (equality operator).

cmos
  • 482
  • 4
  • 14
  • 1
    The equality check is redundant alltogether; your code is asking the overcmplicated "*if its true that true equals true*" when you could simply ask "*if its true*" – InBetween Dec 04 '18 at 10:33
  • Of course you are right, but I wanted to let op see, that to check for equality you have to use another operator. In case of checking a bool value of course, this is redundant. – cmos Dec 04 '18 at 10:37