bravoit

bool

Mar 14th, 2013
1,586
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.84 KB | None | 0 0
  1. public class BoolTest
  2. {
  3.     static void Main()
  4.     {
  5.     //Gán b là true
  6.         bool b = true;
  7.  
  8.         // In b ra. Nếu true in true, flase in false.
  9.         Console.WriteLine(b);
  10.    
  11.     // lấy giá trị ngày hiện tại. ví dụ hm nay này 14/03/2013. Lấy ra 14
  12.         int days = DateTime.Now.DayOfYear;
  13.  
  14.  
  15.         // b sẽ bằng true/flase. Nếu <day> chia hết cho 2 thì là True ngược lại False. OK
  16.         b = (days % 2 == 0);
  17.  
  18.         // Nếu b=true in ra. Ngược lại False in dòng dưới.
  19.         // Viết (b==true) hay (b) cũng tương đương.
  20.          if (b)
  21.         {
  22.             Console.WriteLine("days is an even number");
  23.         }
  24.         else
  25.         {
  26.             Console.WriteLine("days is an odd number");
  27.         }  
  28.     }
  29. }
  30. /* Output:
  31.   True
  32.   days is an <even/odd> number
  33. */
Advertisement
Add Comment
Please, Sign In to add comment