Created
August 18, 2014 18:40
-
-
Save capablaza/5df5f8f32bde12d920f3 to your computer and use it in GitHub Desktop.
Conditional examples use
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
public class Conditionals | |
{ | |
public static void _if() | |
{ | |
int i = 5; | |
if (i == 5) | |
{ | |
Console.WriteLine(string.Format("The value is {0} \n",i)); | |
} | |
} | |
public static void _if_else() | |
{ | |
int i = 6; | |
if (i == 5) | |
{ | |
Console.WriteLine(string.Format("The value is {0} \n", i)); | |
} | |
else | |
{ | |
Console.WriteLine(string.Format("The value {0} isn't {1} \n", i, 5)); | |
} | |
} | |
public static void _if_elseif_else() | |
{ | |
int i = 6; | |
if (i == 5) | |
{ | |
Console.WriteLine(string.Format("The value is {0} \n", i)); | |
} | |
if (i == 6) | |
{ | |
Console.WriteLine(string.Format("The value is {0} \n", 6)); | |
} | |
else | |
{ | |
Console.WriteLine(string.Format("The value {0} isn't {1} \n", i, 5)); | |
} | |
} | |
public static void _switch() | |
{ | |
int i = 6; | |
switch (i) | |
{ | |
case 1: | |
Console.WriteLine("the value is 1"); | |
break; | |
default: | |
Console.WriteLine(string.Format("The value is : {0}", i)); | |
break; | |
} | |
} | |
public static void _ifInline() | |
{ | |
int a = 4; | |
String answer = ""; | |
answer = a == 4 ? "Is 4" : "Isn't 4"; | |
Console.WriteLine(answer); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment