Skip to content

Commit fbf9cb0

Browse files
author
Ron Petrusha
authored
Expanded remarks of VB #If directive (#4921)
* Added a comment to remarks * Addressed review comment
1 parent 7e5142a commit fbf9cb0

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

docs/visual-basic/language-reference/directives/if-then-else-directives.md

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
---
22
title: "#If...Then...#Else Directives"
3-
ms.date: 07/20/2015
3+
ms.date: 04/11/2018
44
ms.prod: .net
5-
ms.suite: ""
65
ms.technology:
76
- "devlang-visual-basic"
87
ms.topic: "article"
@@ -23,9 +22,8 @@ helpviewer_keywords:
2322
- "else directive (#else)"
2423
- "#Else directive [Visual Basic]"
2524
ms.assetid: 10bba104-e3fd-451b-b672-faa472530502
26-
caps.latest.revision: 14
27-
author: dotnet-bot
28-
ms.author: dotnetcontent
25+
author: rpetrusha
26+
ms.author: ronpet
2927
---
3028
# #If...Then...#Else Directives
3129
Conditionally compiles selected blocks of Visual Basic code.
@@ -63,14 +61,29 @@ Conditionally compiles selected blocks of Visual Basic code.
6361
Regardless of the outcome of any evaluation, all expressions are evaluated using `Option Compare Binary`. The `Option Compare` statement does not affect expressions in `#If` and `#ElseIf` statements.
6462

6563
> [!NOTE]
66-
> No single-line form of the `#If`, `#Else`, `#ElseIf`, and `#End If` directives exists. No other code can appear on the same line as any of the directives.
67-
68-
## Example
64+
> No single-line form of the `#If`, `#Else`, `#ElseIf`, and `#End If` directives exists. No other code can appear on the same line as any of the directives.
65+
66+
The statements within a conditional compilation block must be complete logical statements. For example, you cannot conditionally compile only the attributes of a function, but you can conditionally declare the function along with its attributes:
67+
68+
```vb
69+
#If DEBUG Then
70+
<WebMethod()>
71+
Public Function SomeFunction() As String
72+
#Else
73+
<WebMethod(CacheDuration:=86400)>
74+
Public Function SomeFunction() As String
75+
#End If
76+
```
77+
78+
## Example
6979
This example uses the `#If...Then...#Else` construct to determine whether to compile certain statements.
7080

7181
[!code-vb[VbVbalrConditionalComp#1](../../../visual-basic/language-reference/directives/codesnippet/VisualBasic/if-then-else-directives_1.vb)]
7282

7383
## See Also
74-
[#Const Directive](../../../visual-basic/language-reference/directives/const-directive.md)
75-
[If...Then...Else Statement](../../../visual-basic/language-reference/statements/if-then-else-statement.md)
76-
[Conditional Compilation](../../../visual-basic/programming-guide/program-structure/conditional-compilation.md)
84+
[#Const Directive](../../../visual-basic/language-reference/directives/const-directive.md)
85+
[If...Then...Else Statement](../../../visual-basic/language-reference/statements/if-then-else-statement.md)
86+
[Conditional Compilation](../../../visual-basic/programming-guide/program-structure/conditional-compilation.md)
87+
<xref:System.Diagnostics.ConditionalAttribute?displayProperty=nameWithType>
88+
89+

0 commit comments

Comments
 (0)