Please solve this.

  • Thread starter Thread starter bbawa1
  • Start date Start date
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 &&
 
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";
}
 
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))
 
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.






Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
 
The problem is a bit more than just misplaced parens.
See my just-sent explanation.




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
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";
}
 
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.






Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
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 &&
 
Hi, Milosz,

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




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
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.






Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
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 &&
 
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) ?




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
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.






Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
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 &&
 
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.




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
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) ?




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
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.






Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
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 &&
 
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.




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
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) ?




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
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.






Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
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 &&
 
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 ?





Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
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.




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
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) ?




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
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.






Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
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 &&
 
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 ?





Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
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.




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
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) ?




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
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.






Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
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 &&
 
Thanks for clearing that up, Milosz.




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
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 ?





Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
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.




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
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) ?




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
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.






Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
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 &&
 
Back
Top