Differences between If and IIF in VB. NET

Source: Internet
Author: User
Let's take a look at the differences between the two functions.
1.   Private   Function geteachqty () Function Geteachqty ( Byval OBJ As   Object ) As   Integer
If   Isdbnull (OBJ) =   False   Then
Return Convert. toint32 (OBJ)
Else
Return   0
End   If
End Function

2.   Private   Function geteachqty () function geteachqty ( byval OBJ as Object ) as integer
return IIF ( isdbnull (OBJ ), 0 , convert. toint32 (OBJ)

End Function

Same, different, same, different ........

I think it is different. Based on my test results, I guessCode2 closer to code 3

3.   Private   Function geteachqty () Function Geteachqty ( Byval OBJ As   Object ) As   Integer
Dim Resule As   Integer = Convert. toint32 (OBJ)
If   Isdbnull (OBJ) =   False   Then
Return Resule
Else
Return   0
End   If
End Function

If I guess it is true, then the IF and IIF are essentially different and cannot be exchanged at all. You must be careful when using them.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.