IIF Construct, a Handy ShortHand of IF-ELSE
Posted by kinjanshah on September 24, 2008
As I was reviewing the ASP.Net code of one of my friends, I found following thing.
Dim intValue As Integer = 10
Dim blnFlag As Boolean
If intValue = 10 Then
blnFlag = True
Else
blnFlag = False
End If
So, I suggested him a shorthand provided in ASP.NET i.e. IIF Construct.
Syntax:
IIF(<<Expression>> ,<<True Part>>,<<False Part>>)
Explanation:
Expression: The Expression which needs to be evaluated.
True Part: What action to be taken if Expression is True
False Part: What action to be taken if Expression is False
Example:
Dim intValue As Integer = 10
Dim blnFlag As Boolean = IIf(intValue = 10, True, False)
So, above shorthand is very much handy to use.