TRUE IF-statement gets ignored

G

Gabriël

Hi Folks,

If got a piece of code in which a IF-statement is true, but still the ELSE
code is excecuted. (While debuging it constantly jumps to the ELSE, while
the expression, according to the Command Window & Watch is true)

Code:

if (Request.QueryString["Id"] != null)

{

if (ViewState["action"] == "editing")

{

(..)

}

else

{

(..)

}

}



Any help would be appriciated!

Greets,

Gab
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

The line
if (ViewState["action"] == "editing")

should give you a warning, as the left side is an object, not a string:

Possible unintended reference comparison; to get a value comparison, cast
the left hand side to type 'string'


Just do ViewState["action"].ToString()

Cheers,
 
G

Gabriël

Thanks for the two responses!

Still strange the compiler accepts it, the watch didn't complain and it did
run,

Greets,
Gab

Ignacio Machin ( .NET/ C# MVP ) said:
Hi,

The line
if (ViewState["action"] == "editing")

should give you a warning, as the left side is an object, not a string:

Possible unintended reference comparison; to get a value comparison, cast
the left hand side to type 'string'


Just do ViewState["action"].ToString()

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Gabriël said:
Hi Folks,

If got a piece of code in which a IF-statement is true, but still the ELSE
code is excecuted. (While debuging it constantly jumps to the ELSE, while
the expression, according to the Command Window & Watch is true)

Code:

if (Request.QueryString["Id"] != null)

{

if (ViewState["action"] == "editing")

{

(..)

}

else

{

(..)

}

}



Any help would be appriciated!

Greets,

Gab
 

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

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top