473,386 Members | 1,708 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Doesn't go in all iff statements.

Hi,

I have the following code. but if just goes to first if Statement
where I make comparison. but it doesn't go to second if statement.
Colul u please help me with that.
protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{

if(e.Row.RowType == DataControlRowType.DataRow)

//DateTime enddate = DateTime.Now;
//TimeSpan duration = enddate -
Convert.ToDateTime(e.Row.Cells[1]);

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

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

}
if ((Convert.ToInt32(e.Row.Cells[2].Text) >= 27) &&
(Convert.ToInt32(e.Row.Cells[2].Text) <=29))

{

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

}
if ((Convert.ToInt32(e.Row.Cells[2].Text) >= 30) &&
(Convert.ToInt32(e.Row.Cells[2].Text) <=32))

{

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

}

Jun 21 '07 #1
3 1995
Hi there,

C# supports short circuit evaluation, meaning it evaluates its second
operand if necessary, i.e. for && operand only if the first operand is true.

a && b == true only if a and b are true (therefore, if a is false there is
no point to check the second operand)

a || b == true for all cases except a and b are false. Therefore b is tested
only if a equals false

Should be clear now ;-)
--
Milosz
"bb****@yahoo.com" wrote:
Hi,

I have the following code. but if just goes to first if Statement
where I make comparison. but it doesn't go to second if statement.
Colul u please help me with that.
protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{

if(e.Row.RowType == DataControlRowType.DataRow)

//DateTime enddate = DateTime.Now;
//TimeSpan duration = enddate -
Convert.ToDateTime(e.Row.Cells[1]);

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

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

}
if ((Convert.ToInt32(e.Row.Cells[2].Text) >= 27) &&
(Convert.ToInt32(e.Row.Cells[2].Text) <=29))

{

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

}
if ((Convert.ToInt32(e.Row.Cells[2].Text) >= 30) &&
(Convert.ToInt32(e.Row.Cells[2].Text) <=32))

{

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

}

Jun 21 '07 #2
Hi,

Milosz Skalecki [MCAD] wrote:
Hi there,

C# supports short circuit evaluation, meaning it evaluates its second
operand if necessary, i.e. for && operand only if the first operand is true.

a && b == true only if a and b are true (therefore, if a is false there is
no point to check the second operand)

a || b == true for all cases except a and b are false. Therefore b is tested
only if a equals false

Should be clear now ;-)
Which can, BTW, be very dangerous if the developer is not aware of that.

For example:

private bool doSomething()
{
// ... Do something
}

if ( myBoolean || doSomething() )
{
// Bla bla
}

In the case above, if myBoolean is true, then the method doSomething is
never called, which can cause unexpected behaviour.

Greetings,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft.ch
PhotoAlbum: http://www.galasoft.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Jun 22 '07 #3
Hi Laurent,

Yes, I definitely agree. But these are basics, and every C# developer should
be (in theory ;-) aware about short-circuit evaluation.

Best regards

--
Milosz
"Laurent Bugnion, MVP" wrote:
Hi,

Milosz Skalecki [MCAD] wrote:
Hi there,

C# supports short circuit evaluation, meaning it evaluates its second
operand if necessary, i.e. for && operand only if the first operand is true.

a && b == true only if a and b are true (therefore, if a is false there is
no point to check the second operand)

a || b == true for all cases except a and b are false. Therefore b is tested
only if a equals false

Should be clear now ;-)

Which can, BTW, be very dangerous if the developer is not aware of that.

For example:

private bool doSomething()
{
// ... Do something
}

if ( myBoolean || doSomething() )
{
// Bla bla
}

In the case above, if myBoolean is true, then the method doSomething is
never called, which can cause unexpected behaviour.

Greetings,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft.ch
PhotoAlbum: http://www.galasoft.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Jun 22 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: TheDustbustr | last post by:
<code> from __future__ import generators from time import time threads= def sleep(n): print "In Sleep" t=time() while (t+n>time()): yield None
44
by: Mariusz Jedrzejewski | last post by:
Hi, I'll be very grateful if somebody can explain me why my Opera 7.23 (runing under linux) doesn't show me inner tables. Using below code I can see only "inner table 1". There is no problem with...
24
by: Benjamin Doyle | last post by:
In Chip Irek's "A PRIMER ON USING DB2 WITH .NET" (www.15seconds.com), he states that "...ODBC doesn't support DB2 stored procedures. So if you are building an application heavily dependant on...
15
by: Steve | last post by:
I have a form with about 25 fields. In the BeforeUpdate event of the form, I have code that sets the default value of each field to its current value. For a new record, I can put the focus in any...
39
by: slogging_away | last post by:
Hi - I'm running Python 2.4.2 (#67, Sep 28 2005, 12:41:11) on win32, and have a script that makes numerous checks on text files, (configuration files), so discrepancies can be reported. The script...
34
by: electrician | last post by:
Perl has it, Basic has it, Fortran has it. What is so difficult about creating a goto command for JavaScript. Just set up a label and say go to it.
2
by: ojorus | last post by:
Hi! Some questions regarding the mysqli-extension (php5) 1) Prepared statements: If I understand things right, prepared statements will give better performance if you make several similar...
0
by: Gary Herron | last post by:
Ohad Frand wrote: There is no way you can consider 'elif', 'else', 'except', and 'from' statements. However, as someone pointed out, the kwlist from the keyword module is the closest thing we...
0
by: Ohad Frand | last post by:
Hi Thanks a lot for your reply I think the main uses for it is to study the language and to see that I didn't miss anything else or that something is changed from one version to another. The...
3
by: Israel | last post by:
I always wondered why the using command can only take one object. I always find that this isn't sufficient for drawing so I end up always disposing in my finally block but then I have to remember...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.