Advertisement
gur111

Elron - understanding variables and if-elseif-else

Nov 3rd, 2018
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.10 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Elron_Tutoring
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.  
  14.             // Playing with strings
  15.             string name, hello="Hello, ";
  16.             name = "Elron";
  17.             Console.WriteLine("Hello " + name); // Hello Elron
  18.             Console.WriteLine(hello + name); // Hello, Elron
  19.             Console.WriteLine(name + "Hello"); // ElronHello
  20.  
  21.             // Playing with integers
  22.             int num1 = 5, num2 = 15;
  23.             num1 = num1 + 1; // Equal to num1++
  24.             num1++;
  25.             Console.WriteLine(num1); // 7
  26.             Console.WriteLine(num1+num2); // 22
  27.  
  28.             // Mixing strings and integers]
  29.             string num3 = "15";
  30.             Console.WriteLine(num2 + name); // 15Elron
  31.             Console.WriteLine(num2 + num3); // 1515
  32.  
  33.             // Playing with doubles
  34.             double num4 = 15.1;
  35.             num1 = (int) num4;
  36.             Console.WriteLine(num4); // 15.1
  37.             Console.WriteLine(num1); // 15
  38.             num1 = 5;
  39.             num4 = num1;
  40.             Console.WriteLine(num4); // 5
  41.  
  42.             // מוסכמות כתיבה
  43.  
  44.             // Is raining
  45.             // isRaining
  46.  
  47.             // Elron's House
  48.             // elronsHouse
  49.  
  50.             // Eating the icecream
  51.             // eatingTheIcecream
  52.  
  53.             // This is the name for the box
  54.             // thisIsTheNameForTheBox
  55.  
  56.             // this != THIS
  57.             int Num4 = 50;
  58.             Console.WriteLine(Num4); // 50
  59.             Console.WriteLine(num4); // 5
  60.  
  61.             // Playing with bools and if/else
  62.             bool isRaining = true; // Or false
  63.             Console.WriteLine(isRaining == false); // False
  64.             Console.WriteLine(isRaining != false); // True
  65.             bool b1 = true, b2 = false;
  66.             Console.WriteLine(b1 && !b2); // True
  67.             Console.WriteLine(!b1 && b2); // False
  68.             Console.WriteLine(b1 || b2); // True
  69.             Console.WriteLine(b1 || !b2); // True
  70.                               //           T
  71.                               //    F              F
  72.                               // F      F       F     F
  73.             Console.WriteLine( (!b1 && b2) == (b2 != !b1) ); // True
  74.  
  75.             if (isRaining)
  76.                 Console.WriteLine("Inside the if");
  77.  
  78.             Console.WriteLine("Outside the if");
  79.             int num5 = 10;
  80.             string str1 = "10";
  81.             if (num5 + "" == str1)
  82.             {
  83.                 Console.WriteLine("a");
  84.             }
  85.             else if (num5 + 1 == 10) {
  86.                 Console.WriteLine("a");
  87.             }
  88.             else if (num5 + 1 == 11)
  89.             {
  90.                 Console.WriteLine("a");
  91.             }
  92.             else
  93.             {
  94.                 Console.WriteLine("Failed");
  95.             }
  96.             Console.WriteLine("Again outside");
  97.             // Playing with chars
  98.             char c1 = '1', c2 = 'a', c3 = 'A';
  99.            
  100.  
  101.  
  102.         }
  103.     }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement