Please solve this.

B

bbawa1

It says invalid expression term &&

protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{

if
((Convert.ToInt32(e.Row.Cells[2].Text)>=15))&&(Convert.ToInt32(e.Row.Cells[2].Text)>=17);
{

e.Row.Cells[0].CssClass = "sdgStatusOrange";

}

It says invalid expression term &&
 
T

Turkbear

It says invalid expression term &&

protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{

if
((Convert.ToInt32(e.Row.Cells[2].Text)>=15))&&(Convert.ToInt32(e.Row.Cells[2].Text)>=17);
{

e.Row.Cells[0].CssClass = "sdgStatusOrange";

}

It says invalid expression term &&

Check the parens ( maybe):
if
((Convert.ToInt32(e.Row.Cells[2].Text)>=15)&& (Convert.ToInt32(e.Row.Cells[2].Text)>=17)) ;
{

e.Row.Cells[0].CssClass = "sdgStatusOrange";
}
 
M

Mark Rae

It says invalid expression term &&

protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{

if
((Convert.ToInt32(e.Row.Cells[2].Text)>=15))&&(Convert.ToInt32(e.Row.Cells[2].Text)>=17);
{

e.Row.Cells[0].CssClass = "sdgStatusOrange";

}

It says invalid expression term &&

You've got your parentheses slightly confused:

if((Convert.ToInt32(e.Row.Cells[2].Text)>=15)&&(Convert.ToInt32(e.Row.Cells[2].Text)>=17))
 
J

Juan T. Llibre

re:
((Convert.ToInt32(e.Row.Cells[2].Text)>=15))&&(Convert.ToInt32(e.Row.Cells[2].Text)>=17);

You need to use the "regular" AND operator.

Try :

((Convert.ToInt32(e.Row.Cells[2].Text)>=15))&(Convert.ToInt32(e.Row.Cells[2].Text)>=17);

If you use && and e.Row.Cells[2].Text)>=15 is false, e.Row.Cells[2].Text)>=17
is not evaluated (because the result of the AND operation is false no matter what the
value of e.Row.Cells[2].Text)>=17 may be).

This is known as "short-circuit" evaluation...but it requires *both* operands to be true.
In your code, that is not alsways the case.
 
J

Juan T. Llibre

The problem is a bit more than just misplaced parens.
See my just-sent explanation.





Turkbear said:
It says invalid expression term &&

protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{

if
((Convert.ToInt32(e.Row.Cells[2].Text)>=15))&&(Convert.ToInt32(e.Row.Cells[2].Text)>=17);
{

e.Row.Cells[0].CssClass = "sdgStatusOrange";

}

It says invalid expression term &&

Check the parens ( maybe):
if
((Convert.ToInt32(e.Row.Cells[2].Text)>=15)&& (Convert.ToInt32(e.Row.Cells[2].Text)>=17)) ;
{

e.Row.Cells[0].CssClass = "sdgStatusOrange";
}
 
G

Guest

Hi Juan,

In this case, "invalid expression term &&" is caused definitely by misplaced
parentheses, because it is a compiler message ;-) (evaluation would be done
at the runtime). Second, bitwise and & operator will give the same result
(apart from the fact short-circuit is not apllicable) because true & true =
true, false & true = false, false & false = false. Therefore, it should be
corrected to:

if (
(Convert.ToInt32(e.Row.Cells[2].Text) >= 15) &&
(Convert.ToInt32(e.Row.Cells[2].Text) >= 17))
{
e.Row.Cells[0].CssClass = "sdgStatusOrange";
}

Best regards
--
Milosz


Juan T. Llibre said:
re:
((Convert.ToInt32(e.Row.Cells[2].Text)>=15))&&(Convert.ToInt32(e.Row.Cells[2].Text)>=17);

You need to use the "regular" AND operator.

Try :

((Convert.ToInt32(e.Row.Cells[2].Text)>=15))&(Convert.ToInt32(e.Row.Cells[2].Text)>=17);

If you use && and e.Row.Cells[2].Text)>=15 is false, e.Row.Cells[2].Text)>=17
is not evaluated (because the result of the AND operation is false no matter what the
value of e.Row.Cells[2].Text)>=17 may be).

This is known as "short-circuit" evaluation...but it requires *both* operands to be true.
In your code, that is not alsways the case.







It says invalid expression term &&

protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{

if
((Convert.ToInt32(e.Row.Cells[2].Text)>=15))&&(Convert.ToInt32(e.Row.Cells[2].Text)>=17);
{

e.Row.Cells[0].CssClass = "sdgStatusOrange";

}

It says invalid expression term &&
 
J

Juan T. Llibre

Hi, Milosz,

In that case, what happens if Convert.ToInt32(e.Row.Cells[2].Text = 14) ?





Milosz Skalecki said:
Hi Juan,

In this case, "invalid expression term &&" is caused definitely by misplaced
parentheses, because it is a compiler message ;-) (evaluation would be done
at the runtime). Second, bitwise and & operator will give the same result
(apart from the fact short-circuit is not apllicable) because true & true =
true, false & true = false, false & false = false. Therefore, it should be
corrected to:

if (
(Convert.ToInt32(e.Row.Cells[2].Text) >= 15) &&
(Convert.ToInt32(e.Row.Cells[2].Text) >= 17))
{
e.Row.Cells[0].CssClass = "sdgStatusOrange";
}

Best regards
--
Milosz


Juan T. Llibre said:
re:
((Convert.ToInt32(e.Row.Cells[2].Text)>=15))&&(Convert.ToInt32(e.Row.Cells[2].Text)>=17);

You need to use the "regular" AND operator.

Try :

((Convert.ToInt32(e.Row.Cells[2].Text)>=15))&(Convert.ToInt32(e.Row.Cells[2].Text)>=17);

If you use && and e.Row.Cells[2].Text)>=15 is false, e.Row.Cells[2].Text)>=17
is not evaluated (because the result of the AND operation is false no matter what the
value of e.Row.Cells[2].Text)>=17 may be).

This is known as "short-circuit" evaluation...but it requires *both* operands to be true.
In your code, that is not alsways the case.







It says invalid expression term &&

protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{

if
((Convert.ToInt32(e.Row.Cells[2].Text)>=15))&&(Convert.ToInt32(e.Row.Cells[2].Text)>=17);
{

e.Row.Cells[0].CssClass = "sdgStatusOrange";

}

It says invalid expression term &&
 
G

Guest

Good morning Juan

Did you mean if the text in cell equals "14"

if (
(Convert.ToInt32(e.Row.Cells[2].Text) >= 15) &&
(Convert.ToInt32(e.Row.Cells[2].Text) >= 17))
{
e.Row.Cells[0].CssClass = "sdgStatusOrange";
}

then statement inside is not going to be reached, simply because the first
condition is false, and short-circuit evaluation for && operator skips the
second operand. I understand your confusion as I have seen this guy's
previous post, but in this case it was just misplaced parentheses ;-)
--
Milosz


Juan T. Llibre said:
Hi, Milosz,

In that case, what happens if Convert.ToInt32(e.Row.Cells[2].Text = 14) ?





Milosz Skalecki said:
Hi Juan,

In this case, "invalid expression term &&" is caused definitely by misplaced
parentheses, because it is a compiler message ;-) (evaluation would be done
at the runtime). Second, bitwise and & operator will give the same result
(apart from the fact short-circuit is not apllicable) because true & true =
true, false & true = false, false & false = false. Therefore, it should be
corrected to:

if (
(Convert.ToInt32(e.Row.Cells[2].Text) >= 15) &&
(Convert.ToInt32(e.Row.Cells[2].Text) >= 17))
{
e.Row.Cells[0].CssClass = "sdgStatusOrange";
}

Best regards
--
Milosz


Juan T. Llibre said:
re:
((Convert.ToInt32(e.Row.Cells[2].Text)>=15))&&(Convert.ToInt32(e.Row.Cells[2].Text)>=17);

You need to use the "regular" AND operator.

Try :

((Convert.ToInt32(e.Row.Cells[2].Text)>=15))&(Convert.ToInt32(e.Row.Cells[2].Text)>=17);

If you use && and e.Row.Cells[2].Text)>=15 is false, e.Row.Cells[2].Text)>=17
is not evaluated (because the result of the AND operation is false no matter what the
value of e.Row.Cells[2].Text)>=17 may be).

This is known as "short-circuit" evaluation...but it requires *both* operands to be true.
In your code, that is not alsways the case.







It says invalid expression term &&

protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{

if
((Convert.ToInt32(e.Row.Cells[2].Text)>=15))&&(Convert.ToInt32(e.Row.Cells[2].Text)>=17);
{

e.Row.Cells[0].CssClass = "sdgStatusOrange";

}

It says invalid expression term &&
 
J

Juan T. Llibre

re:
!> Did you mean if the text in cell equals "14"

Yes.

re:
!> then statement inside is not going to be reached, simply because the first
!> condition is false, and short-circuit evaluation for && operator skips the second operand.

That's exactly what I explained...and that's an undesirable "feature".
That's why he needs to change the operator.

re:
!> I understand your confusion

There's no confusion.

He should change both the parens *and* the operator,
the first as you suggest; the second as I suggest.

Doing that will cover all the bases for him.





Milosz Skalecki said:
Good morning Juan

Did you mean if the text in cell equals "14"

if (
(Convert.ToInt32(e.Row.Cells[2].Text) >= 15) &&
(Convert.ToInt32(e.Row.Cells[2].Text) >= 17))
{
e.Row.Cells[0].CssClass = "sdgStatusOrange";
}

then statement inside is not going to be reached, simply because the first
condition is false, and short-circuit evaluation for && operator skips the
second operand. I understand your confusion as I have seen this guy's
previous post, but in this case it was just misplaced parentheses ;-)
--
Milosz


Juan T. Llibre said:
Hi, Milosz,

In that case, what happens if Convert.ToInt32(e.Row.Cells[2].Text = 14) ?





Milosz Skalecki said:
Hi Juan,

In this case, "invalid expression term &&" is caused definitely by misplaced
parentheses, because it is a compiler message ;-) (evaluation would be done
at the runtime). Second, bitwise and & operator will give the same result
(apart from the fact short-circuit is not apllicable) because true & true =
true, false & true = false, false & false = false. Therefore, it should be
corrected to:

if (
(Convert.ToInt32(e.Row.Cells[2].Text) >= 15) &&
(Convert.ToInt32(e.Row.Cells[2].Text) >= 17))
{
e.Row.Cells[0].CssClass = "sdgStatusOrange";
}

Best regards
--
Milosz


:

re:
((Convert.ToInt32(e.Row.Cells[2].Text)>=15))&&(Convert.ToInt32(e.Row.Cells[2].Text)>=17);

You need to use the "regular" AND operator.

Try :

((Convert.ToInt32(e.Row.Cells[2].Text)>=15))&(Convert.ToInt32(e.Row.Cells[2].Text)>=17);

If you use && and e.Row.Cells[2].Text)>=15 is false, e.Row.Cells[2].Text)>=17
is not evaluated (because the result of the AND operation is false no matter what the
value of e.Row.Cells[2].Text)>=17 may be).

This is known as "short-circuit" evaluation...but it requires *both* operands to be true.
In your code, that is not alsways the case.







It says invalid expression term &&

protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{

if
((Convert.ToInt32(e.Row.Cells[2].Text)>=15))&&(Convert.ToInt32(e.Row.Cells[2].Text)>=17);
{

e.Row.Cells[0].CssClass = "sdgStatusOrange";

}

It says invalid expression term &&
 
G

Guest

Juan,

Come on, i can't see any logical exlanation in changing && operator to & for
this case :). First of all, logically, his "if" statement could be
simplified changed to:
if (Convert.ToInt32(e.Row.Cells[2].Text) >= 17)
{
e.Row.Cells[0].CssClass = "sdgStatusOrange";
}
simply because the only numbers that meet both criteria are >= 17. Second,
if the first operand (Convert.ToInt32(e.Row.Cells[2].Text) >= 15) would
return false, second could not be true (logically). Please also note he used
&& therefore there is not point to test the second operand as you're trying
to point out. Third, it was definitely compiler error (syntax error) which
has nothing to do with runtime evaluation.

Take it easy mate ;-)

Best regards
--
Milosz


Juan T. Llibre said:
re:
!> Did you mean if the text in cell equals "14"

Yes.

re:
!> then statement inside is not going to be reached, simply because the first
!> condition is false, and short-circuit evaluation for && operator skips the second operand.

That's exactly what I explained...and that's an undesirable "feature".
That's why he needs to change the operator.

re:
!> I understand your confusion

There's no confusion.

He should change both the parens *and* the operator,
the first as you suggest; the second as I suggest.

Doing that will cover all the bases for him.





Milosz Skalecki said:
Good morning Juan

Did you mean if the text in cell equals "14"

if (
(Convert.ToInt32(e.Row.Cells[2].Text) >= 15) &&
(Convert.ToInt32(e.Row.Cells[2].Text) >= 17))
{
e.Row.Cells[0].CssClass = "sdgStatusOrange";
}

then statement inside is not going to be reached, simply because the first
condition is false, and short-circuit evaluation for && operator skips the
second operand. I understand your confusion as I have seen this guy's
previous post, but in this case it was just misplaced parentheses ;-)
--
Milosz


Juan T. Llibre said:
Hi, Milosz,

In that case, what happens if Convert.ToInt32(e.Row.Cells[2].Text = 14) ?





Hi Juan,

In this case, "invalid expression term &&" is caused definitely by misplaced
parentheses, because it is a compiler message ;-) (evaluation would be done
at the runtime). Second, bitwise and & operator will give the same result
(apart from the fact short-circuit is not apllicable) because true & true =
true, false & true = false, false & false = false. Therefore, it should be
corrected to:

if (
(Convert.ToInt32(e.Row.Cells[2].Text) >= 15) &&
(Convert.ToInt32(e.Row.Cells[2].Text) >= 17))
{
e.Row.Cells[0].CssClass = "sdgStatusOrange";
}

Best regards
--
Milosz


:

re:
((Convert.ToInt32(e.Row.Cells[2].Text)>=15))&&(Convert.ToInt32(e.Row.Cells[2].Text)>=17);

You need to use the "regular" AND operator.

Try :

((Convert.ToInt32(e.Row.Cells[2].Text)>=15))&(Convert.ToInt32(e.Row.Cells[2].Text)>=17);

If you use && and e.Row.Cells[2].Text)>=15 is false, e.Row.Cells[2].Text)>=17
is not evaluated (because the result of the AND operation is false no matter what the
value of e.Row.Cells[2].Text)>=17 may be).

This is known as "short-circuit" evaluation...but it requires *both* operands to be true.
In your code, that is not alsways the case.







It says invalid expression term &&

protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{

if
((Convert.ToInt32(e.Row.Cells[2].Text)>=15))&&(Convert.ToInt32(e.Row.Cells[2].Text)>=17);
{

e.Row.Cells[0].CssClass = "sdgStatusOrange";

}

It says invalid expression term &&
 
J

Juan T. Llibre

re:
!> Take it easy mate ;-)

Has anything I've written implied that I'm not ?

;-)

re:
!> his "if" statement could be simplified changed to:

I agree, but the problem, *as stated*, won't be resolved just by changing the parens,
because, if the condition (Convert.ToInt32(e.Row.Cells[2].Text) >= 15) is *false*,
changing the parens won't help him.

He needs to do both what you suggested *and* what I suggested,
if the original conditions remain as stated by him.

Whether he should change his conditions, and not leave them as stated, is another issue.

;-)

re:
!> also note he used && therefore there is not point to test the second operand

Again, what if the first operand is false ?






Milosz Skalecki said:
Juan,

Come on, i can't see any logical exlanation in changing && operator to & for
this case :). First of all, logically, his "if" statement could be
simplified changed to:
if (Convert.ToInt32(e.Row.Cells[2].Text) >= 17)
{
e.Row.Cells[0].CssClass = "sdgStatusOrange";
}
simply because the only numbers that meet both criteria are >= 17. Second,
if the first operand (Convert.ToInt32(e.Row.Cells[2].Text) >= 15) would
return false, second could not be true (logically). Please also note he used
&& therefore there is not point to test the second operand as you're trying
to point out. Third, it was definitely compiler error (syntax error) which
has nothing to do with runtime evaluation.

Take it easy mate ;-)

Best regards
--
Milosz


Juan T. Llibre said:
re:
!> Did you mean if the text in cell equals "14"

Yes.

re:
!> then statement inside is not going to be reached, simply because the first
!> condition is false, and short-circuit evaluation for && operator skips the second operand.

That's exactly what I explained...and that's an undesirable "feature".
That's why he needs to change the operator.

re:
!> I understand your confusion

There's no confusion.

He should change both the parens *and* the operator,
the first as you suggest; the second as I suggest.

Doing that will cover all the bases for him.





Milosz Skalecki said:
Good morning Juan

Did you mean if the text in cell equals "14"

if (
(Convert.ToInt32(e.Row.Cells[2].Text) >= 15) &&
(Convert.ToInt32(e.Row.Cells[2].Text) >= 17))
{
e.Row.Cells[0].CssClass = "sdgStatusOrange";
}

then statement inside is not going to be reached, simply because the first
condition is false, and short-circuit evaluation for && operator skips the
second operand. I understand your confusion as I have seen this guy's
previous post, but in this case it was just misplaced parentheses ;-)
--
Milosz


:

Hi, Milosz,

In that case, what happens if Convert.ToInt32(e.Row.Cells[2].Text = 14) ?





Hi Juan,

In this case, "invalid expression term &&" is caused definitely by misplaced
parentheses, because it is a compiler message ;-) (evaluation would be done
at the runtime). Second, bitwise and & operator will give the same result
(apart from the fact short-circuit is not apllicable) because true & true =
true, false & true = false, false & false = false. Therefore, it should be
corrected to:

if (
(Convert.ToInt32(e.Row.Cells[2].Text) >= 15) &&
(Convert.ToInt32(e.Row.Cells[2].Text) >= 17))
{
e.Row.Cells[0].CssClass = "sdgStatusOrange";
}

Best regards
--
Milosz


:

re:
((Convert.ToInt32(e.Row.Cells[2].Text)>=15))&&(Convert.ToInt32(e.Row.Cells[2].Text)>=17);

You need to use the "regular" AND operator.

Try :

((Convert.ToInt32(e.Row.Cells[2].Text)>=15))&(Convert.ToInt32(e.Row.Cells[2].Text)>=17);

If you use && and e.Row.Cells[2].Text)>=15 is false, e.Row.Cells[2].Text)>=17
is not evaluated (because the result of the AND operation is false no matter what the
value of e.Row.Cells[2].Text)>=17 may be).

This is known as "short-circuit" evaluation...but it requires *both* operands to be true.
In your code, that is not alsways the case.







It says invalid expression term &&

protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{

if
((Convert.ToInt32(e.Row.Cells[2].Text)>=15))&&(Convert.ToInt32(e.Row.Cells[2].Text)>=17);
{

e.Row.Cells[0].CssClass = "sdgStatusOrange";

}

It says invalid expression term &&
 
G

Guest

Howdy Juan,

I just wanted to point out that applying & instead of && wouldn't change
anything, because he's had syntax error.
Again, what if the first operand is false ?

I have answered this question already. For both operators (&& and &) you
will get the same result.

1. && operator

Let simplify it

string str = "12";

(Convert.ToInt32(str) >= 15) &&
(Convert.ToInt32(str) >= 17))

cis equivalent to

(12 >= 15) && (12 >= 17)
false && false = false

please note it apllies for shortcirtuit evaluation as well

2. & operator

false & false = false

which is the same result.

As you can see apllying the only difference between && and & for logical
arguments is that bitwise AND does not use short circuit evaluation.

That's why forcing second operand to be evaluated would not change anything
at all.

Hope it is clear now.

Best regards Juan
--
Milosz


Juan T. Llibre said:
re:
!> Take it easy mate ;-)

Has anything I've written implied that I'm not ?

;-)

re:
!> his "if" statement could be simplified changed to:

I agree, but the problem, *as stated*, won't be resolved just by changing the parens,
because, if the condition (Convert.ToInt32(e.Row.Cells[2].Text) >= 15) is *false*,
changing the parens won't help him.

He needs to do both what you suggested *and* what I suggested,
if the original conditions remain as stated by him.

Whether he should change his conditions, and not leave them as stated, is another issue.

;-)

re:
!> also note he used && therefore there is not point to test the second operand

Again, what if the first operand is false ?






Milosz Skalecki said:
Juan,

Come on, i can't see any logical exlanation in changing && operator to & for
this case :). First of all, logically, his "if" statement could be
simplified changed to:
if (Convert.ToInt32(e.Row.Cells[2].Text) >= 17)
{
e.Row.Cells[0].CssClass = "sdgStatusOrange";
}
simply because the only numbers that meet both criteria are >= 17. Second,
if the first operand (Convert.ToInt32(e.Row.Cells[2].Text) >= 15) would
return false, second could not be true (logically). Please also note he used
&& therefore there is not point to test the second operand as you're trying
to point out. Third, it was definitely compiler error (syntax error) which
has nothing to do with runtime evaluation.

Take it easy mate ;-)

Best regards
--
Milosz


Juan T. Llibre said:
re:
!> Did you mean if the text in cell equals "14"

Yes.

re:
!> then statement inside is not going to be reached, simply because the first
!> condition is false, and short-circuit evaluation for && operator skips the second operand.

That's exactly what I explained...and that's an undesirable "feature".
That's why he needs to change the operator.

re:
!> I understand your confusion

There's no confusion.

He should change both the parens *and* the operator,
the first as you suggest; the second as I suggest.

Doing that will cover all the bases for him.





Good morning Juan

Did you mean if the text in cell equals "14"

if (
(Convert.ToInt32(e.Row.Cells[2].Text) >= 15) &&
(Convert.ToInt32(e.Row.Cells[2].Text) >= 17))
{
e.Row.Cells[0].CssClass = "sdgStatusOrange";
}

then statement inside is not going to be reached, simply because the first
condition is false, and short-circuit evaluation for && operator skips the
second operand. I understand your confusion as I have seen this guy's
previous post, but in this case it was just misplaced parentheses ;-)
--
Milosz


:

Hi, Milosz,

In that case, what happens if Convert.ToInt32(e.Row.Cells[2].Text = 14) ?





Hi Juan,

In this case, "invalid expression term &&" is caused definitely by misplaced
parentheses, because it is a compiler message ;-) (evaluation would be done
at the runtime). Second, bitwise and & operator will give the same result
(apart from the fact short-circuit is not apllicable) because true & true =
true, false & true = false, false & false = false. Therefore, it should be
corrected to:

if (
(Convert.ToInt32(e.Row.Cells[2].Text) >= 15) &&
(Convert.ToInt32(e.Row.Cells[2].Text) >= 17))
{
e.Row.Cells[0].CssClass = "sdgStatusOrange";
}

Best regards
--
Milosz


:

re:
((Convert.ToInt32(e.Row.Cells[2].Text)>=15))&&(Convert.ToInt32(e.Row.Cells[2].Text)>=17);

You need to use the "regular" AND operator.

Try :

((Convert.ToInt32(e.Row.Cells[2].Text)>=15))&(Convert.ToInt32(e.Row.Cells[2].Text)>=17);

If you use && and e.Row.Cells[2].Text)>=15 is false, e.Row.Cells[2].Text)>=17
is not evaluated (because the result of the AND operation is false no matter what the
value of e.Row.Cells[2].Text)>=17 may be).

This is known as "short-circuit" evaluation...but it requires *both* operands to be true.
In your code, that is not alsways the case.







It says invalid expression term &&

protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{

if
((Convert.ToInt32(e.Row.Cells[2].Text)>=15))&&(Convert.ToInt32(e.Row.Cells[2].Text)>=17);
{

e.Row.Cells[0].CssClass = "sdgStatusOrange";

}

It says invalid expression term &&
 
J

Juan T. Llibre

Thanks for clearing that up, Milosz.





Milosz Skalecki said:
Howdy Juan,

I just wanted to point out that applying & instead of && wouldn't change
anything, because he's had syntax error.
Again, what if the first operand is false ?

I have answered this question already. For both operators (&& and &) you
will get the same result.

1. && operator

Let simplify it

string str = "12";

(Convert.ToInt32(str) >= 15) &&
(Convert.ToInt32(str) >= 17))

cis equivalent to

(12 >= 15) && (12 >= 17)
false && false = false

please note it apllies for shortcirtuit evaluation as well

2. & operator

false & false = false

which is the same result.

As you can see apllying the only difference between && and & for logical
arguments is that bitwise AND does not use short circuit evaluation.

That's why forcing second operand to be evaluated would not change anything
at all.

Hope it is clear now.

Best regards Juan
--
Milosz


Juan T. Llibre said:
re:
!> Take it easy mate ;-)

Has anything I've written implied that I'm not ?

;-)

re:
!> his "if" statement could be simplified changed to:

I agree, but the problem, *as stated*, won't be resolved just by changing the parens,
because, if the condition (Convert.ToInt32(e.Row.Cells[2].Text) >= 15) is *false*,
changing the parens won't help him.

He needs to do both what you suggested *and* what I suggested,
if the original conditions remain as stated by him.

Whether he should change his conditions, and not leave them as stated, is another issue.

;-)

re:
!> also note he used && therefore there is not point to test the second operand

Again, what if the first operand is false ?






Milosz Skalecki said:
Juan,

Come on, i can't see any logical exlanation in changing && operator to & for
this case :). First of all, logically, his "if" statement could be
simplified changed to:
if (Convert.ToInt32(e.Row.Cells[2].Text) >= 17)
{
e.Row.Cells[0].CssClass = "sdgStatusOrange";
}
simply because the only numbers that meet both criteria are >= 17. Second,
if the first operand (Convert.ToInt32(e.Row.Cells[2].Text) >= 15) would
return false, second could not be true (logically). Please also note he used
&& therefore there is not point to test the second operand as you're trying
to point out. Third, it was definitely compiler error (syntax error) which
has nothing to do with runtime evaluation.

Take it easy mate ;-)

Best regards
--
Milosz


:

re:
!> Did you mean if the text in cell equals "14"

Yes.

re:
!> then statement inside is not going to be reached, simply because the first
!> condition is false, and short-circuit evaluation for && operator skips the second operand.

That's exactly what I explained...and that's an undesirable "feature".
That's why he needs to change the operator.

re:
!> I understand your confusion

There's no confusion.

He should change both the parens *and* the operator,
the first as you suggest; the second as I suggest.

Doing that will cover all the bases for him.





Good morning Juan

Did you mean if the text in cell equals "14"

if (
(Convert.ToInt32(e.Row.Cells[2].Text) >= 15) &&
(Convert.ToInt32(e.Row.Cells[2].Text) >= 17))
{
e.Row.Cells[0].CssClass = "sdgStatusOrange";
}

then statement inside is not going to be reached, simply because the first
condition is false, and short-circuit evaluation for && operator skips the
second operand. I understand your confusion as I have seen this guy's
previous post, but in this case it was just misplaced parentheses ;-)
--
Milosz


:

Hi, Milosz,

In that case, what happens if Convert.ToInt32(e.Row.Cells[2].Text = 14) ?





Hi Juan,

In this case, "invalid expression term &&" is caused definitely by misplaced
parentheses, because it is a compiler message ;-) (evaluation would be done
at the runtime). Second, bitwise and & operator will give the same result
(apart from the fact short-circuit is not apllicable) because true & true =
true, false & true = false, false & false = false. Therefore, it should be
corrected to:

if (
(Convert.ToInt32(e.Row.Cells[2].Text) >= 15) &&
(Convert.ToInt32(e.Row.Cells[2].Text) >= 17))
{
e.Row.Cells[0].CssClass = "sdgStatusOrange";
}

Best regards
--
Milosz


:

re:
((Convert.ToInt32(e.Row.Cells[2].Text)>=15))&&(Convert.ToInt32(e.Row.Cells[2].Text)>=17);

You need to use the "regular" AND operator.

Try :

((Convert.ToInt32(e.Row.Cells[2].Text)>=15))&(Convert.ToInt32(e.Row.Cells[2].Text)>=17);

If you use && and e.Row.Cells[2].Text)>=15 is false, e.Row.Cells[2].Text)>=17
is not evaluated (because the result of the AND operation is false no matter what the
value of e.Row.Cells[2].Text)>=17 may be).

This is known as "short-circuit" evaluation...but it requires *both* operands to be
true.
In your code, that is not alsways the case.







It says invalid expression term &&

protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{

if
((Convert.ToInt32(e.Row.Cells[2].Text)>=15))&&(Convert.ToInt32(e.Row.Cells[2].Text)>=17);
{

e.Row.Cells[0].CssClass = "sdgStatusOrange";

}

It says invalid expression term &&
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top