Jump to content


Photo

C# Basics: If and Conditionals


  • Please log in to reply
1 reply to this topic

#1 jream

jream

    Administrator

  • Administrators
  • 52 posts

Posted 26 January 2013 - 04:04 AM

These are some examples of Conditional statements in C#.

 

If

int foo = 5;
if (foo > 3) {
  Console.WriteLine("true");
}

if else

int foo = 5;
if (foo > 10) {
  Console.WriteLine("true");
} else {
  Console.WriteLine("false");
}

 

else if

int foo = 5;
if (foo > 10) {
  Console.WriteLine("true");
} else if (foo > 5 {
  Console.WriteLine("kinda true");
} else {
  Console.WriteLine("false");}

 

Ternary (Shorthand if/else)
int foo = 5;
int bar = foo > 10 ? true : false; 
Console.WriteLine(bar);
 
Switch
int foo = 25;
switch (foo) {
  case 10:
    Console.WriteLine(10);
    break;
  case 24:
  case 25:
    Console.WriteLine("24 or 25");
    break;
  default:
    Console.WriteLine("I dont know";
}

 



#2 bun_cuoi_lam

bun_cuoi_lam

    Newbie

  • Members
  • Pip
  • 9 posts

Posted 26 January 2013 - 02:18 PM

Thank. I see it like other language programme :)

Hope you make  more more like it. thanks






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users