interviews.dotnetthread.com

↑ Grab this Headline Animator

Thursday, November 20, 2008

Difference Between IF and IIF Statement in .Net?

IF is called as conditional operator and we can use it both vb.net as well c#.net.

But IIF is the ternary operator, it will take three parameter like expression,true,false. If the expression result is true then it will return TRUE otherwise return FALSE. There is no IIF concept in the c#.net.

syntax for IF:
vb.net
if i==0 Then
MsgBox("true")
else
MsgBox("false")

c#.net
if(i==0)
MessageBox("true")
else
MessageBox("false")

syntax for IIF:

IIF(Expression,true,false)

Example
Dim AboutVB As String = "Great"
MsgBox( _
IIf(AboutVB = "Great", "Oh Ja!", "Bummer"))

Output:"Oh Ja!"

Go through the below link:
http://visualbasic.about.com/od/usingvbnet/a/ifop.htm

Submit this story to DotNetKicks

1 comment:

masoud said...

do you ever write code for vb? :)

in vb we haven't ' == ',you have to use single one.like this :

if i=0 Then
MsgBox("true")
else
MsgBox("false")

Post a Comment

Post your comments/questions/feedback for this Article.

 

Latest Articles