-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added snippets for conditional logical operators (#442)
- Loading branch information
Showing
3 changed files
with
73 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
snippets/csharp/language-reference/operators/ConditionalLogicalOperatorsExamples.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System; | ||
|
||
namespace operators | ||
{ | ||
public static class ConditionalLogicalOperatorsExamples | ||
{ | ||
public static void Examples() | ||
{ | ||
ConditionalAnd(); | ||
ConditionalOr(); | ||
} | ||
|
||
private static void ConditionalAnd() | ||
{ | ||
// <SnippetAnd> | ||
bool SecondOperand() | ||
{ | ||
Console.WriteLine("Second operand is evaluated."); | ||
return true; | ||
} | ||
|
||
bool a = false && SecondOperand(); | ||
Console.WriteLine(a); | ||
// Output: | ||
// False | ||
|
||
bool b = true && SecondOperand(); | ||
Console.WriteLine(b); | ||
// Output: | ||
// Second operand is evaluated. | ||
// True | ||
// </SnippetAnd> | ||
} | ||
|
||
private static void ConditionalOr() | ||
{ | ||
// <SnippetOr> | ||
bool SecondOperand() | ||
{ | ||
Console.WriteLine("Second operand is evaluated."); | ||
return true; | ||
} | ||
|
||
bool a = true || SecondOperand(); | ||
Console.WriteLine(a); | ||
// Output: | ||
// True | ||
|
||
bool b = false || SecondOperand(); | ||
Console.WriteLine(b); | ||
// Output: | ||
// Second operand is evaluated. | ||
// True | ||
// </SnippetOr> | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters