Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
If statement
Message
From
28/02/2008 10:50:13
 
 
To
28/02/2008 09:39:38
Jerry Tovar
Dana Corporation Dana It
Maumee, Ohio, United States
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Environment versions
Environment:
C# 2.0
Miscellaneous
Thread ID:
01297350
Message ID:
01297388
Views:
13
Jerry,

this

>if (myvar1 == "") myvar = myvar2; myvar = myvar1;

is the same as this

> if (myvar1 == "") myvar = myvar2;
> myvar = myvar1;

Which means, that "myvar = myvar1" will always be executed.

If you want an if...else construct in a single line code, you might use the following syntax:

myvar = (myvar1=="") ? myvar2 : myvar1;

It's similar to the IIF() function of VFP.
Holger Vorberg
Germany
Previous
Reply
Map
View

Click here to load this message in the networking platform