From fc58f59710d663e43bb6cd40b475cc16fad5ed1b Mon Sep 17 00:00:00 2001 From: Patryk Buda Date: Thu, 21 Mar 2019 17:43:45 +0000 Subject: [PATCH] Short if Else Statements (#28225) * Short if Else Statements * Update index.md --- guide/english/csharp/if-else-statement/index.md | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/guide/english/csharp/if-else-statement/index.md b/guide/english/csharp/if-else-statement/index.md index 487e017a78..2091365358 100644 --- a/guide/english/csharp/if-else-statement/index.md +++ b/guide/english/csharp/if-else-statement/index.md @@ -2,12 +2,13 @@ title: If Else Statement --- -# If Else Statement +# If Else Statement The If-Else statement executes a block of code depending on whether your precondition is fullfilled or not. ## Example -``` + +```c# if(boolean expression) { @@ -21,7 +22,7 @@ else int Price = 30; -If (Price = 30) +If (Price == 30) { Console.WriteLine("Price is equal to 30."); } @@ -32,9 +33,19 @@ Else } ``` + + Since we already declared our int Price to be 30, this will be the expected output. ## Output ``` Price is equal to 30. ``` +## Shorten If Else Statement + +We can use the ternary :? which is great for short if else statements. +For example: +```C# +int Price=30; +(Price==30)?Console.WriteLine("Price is Equal to 30."):Console.WriteLine("Price is Not Equal to 30.") +```