Witcher
Witcher

Reputation: 71

Operator '&&' cannot be applied to operands of type 'int' and 'bool'

if (Console.CursorTop=3 && Console.CursorLeft==7) {
    Console.WriteLine();
}

there is an error

Error   1   Operator '&&' cannot be applied to operands of type 'int' and 'bool'    

Why is it not working?

Upvotes: 2

Views: 27070

Answers (4)

Vahid Farahmandian
Vahid Farahmandian

Reputation: 6568

In C# = is not used for comparison of two values. In order to make a comparison between two values you need to put == in your statement.

if (Console.CursorTop**==**3 && Console.CursorLeft==7) {
     Console.WriteLine();
}

Upvotes: 1

jlunavtgrad
jlunavtgrad

Reputation: 1015

If you are trying to compare CursorTop to 3 then you need if (Console.CursorTop==3 && Console.CursorLeft==7)

Upvotes: 2

irfanmcsd
irfanmcsd

Reputation: 6561

Correct your syntax, replace =3 with ==3

if (Console.CursorTop==3 && Console.CursorLeft==7)
{
    Console.WriteLine();
}

Upvotes: 3

Daniel A. White
Daniel A. White

Reputation: 190945

Don't you mean (notice the double equal signs)

Console.CursorTop == 3

other wise its an assignment.

Upvotes: 12

Related Questions