What is the difference between If and #If?

K

kai

Hi, All
What is the the difference between If and #If? I read some VB.NET books,
sometimes I see #If, but cannot tell why. Please help.

Thanks


Kai
 
H

Herfried K. Wagner [MVP]

Kai,

* "kai said:
What is the the difference between If and #If? I read some VB.NET books,
sometimes I see #If, but cannot tell why. Please help.

If you are using VS.NET or VB.NET Standard, just set the cursor onto the
'If' or '#If' in your code window and press the F1 key.
 
S

Scott M.

From the MSDN help:

On the surface, the behavior of the #If...Then...#Else directives appears
the same as that of the If...Then...Else statements. However, the
#If.Then.#Else directives evaluate what is compiled by the compiler, whereas
the If.Then.Else statements evaluate conditions at run time.
 
P

Peter Huang

Hi Kai,

Thanks for posting in the community.

First of all, I would like to confirm my understanding of your issue.
From your description, I understand that you are confused about the if and
#if statement in VB.NET.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

#If...Then...#Else Directives is used when conditionally compiles selected
blocks of Visual Basic code. The statement will be evaluated in compiling
time.

while If...Then...Else Statements is used when conditionally executes a
group of statements, depending on the value of an expression. It is
evalulated in run time.


#If...Then...#Else Directives
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/
vadirif.asp

If...Then...Else Statements
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/
vastmif.asp

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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

Top