nahidjamalli

Lesson #2

Feb 16th, 2020
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.48 KB | None | 0 0
  1. namespace MyNamespace
  2. {
  3.     class Program
  4.     {
  5.         static void Main(string[] args)
  6.         {
  7.             // Types
  8.             // 1. Value memory size
  9.             // 9456 - 32 bits
  10.             // int i = 4;
  11.             // byte b = 4;
  12.  
  13.             // 2. Value kind
  14.             // int i1 = "1"; ERROR!
  15.             // int i2 = 4.8; ERROR!
  16.             // 'A' => 65
  17.             // int i3 = 'A';
  18.  
  19.             // 3. Value operators
  20.             // int i1 = 3;
  21.             // i1 = i1 + 32;
  22.             // bool b1 = false;
  23.             // b1 = !b1;
  24.             // string str = "AZE"; // string is reference type
  25.             // str = str * 56; ERROR
  26.             // str = str + "RBAIJAN";
  27.  
  28.             // Value Types
  29.             // int a = 2;
  30.             // int b = 54;
  31.  
  32.             // 'b' assign to 'a'
  33.             // a = b; // a = 54, b = 54
  34.             // a = 34; // a = 34, b = 54
  35.             // System.Console.WriteLine("b: " + b);
  36.             /*
  37.             MyStruct ms1 = new MyStruct();
  38.             ms1.x = 1;
  39.             ms1.y = 2;
  40.             ms1.z = 3;
  41.  
  42.             MyStruct ms2 = new MyStruct();
  43.             ms2.x = 4;
  44.             ms2.y = 5;
  45.             ms2.z = 6;
  46.  
  47.             ms1 = ms2; // Copy
  48.             ms2.x = 10;
  49.             ms2.y = 11;
  50.             ms2.z = 12;
  51.  
  52.             System.Console.WriteLine(ms1.x);
  53.             System.Console.WriteLine(ms1.y);
  54.             System.Console.WriteLine(ms1.z);
  55.             */
  56.             /*
  57.             // Reference Types
  58.             MyClass mc1 = new MyClass();
  59.             mc1.x = 1;
  60.             mc1.y = 2;
  61.             mc1.z = 3;
  62.  
  63.             MyClass mc2 = new MyClass();
  64.             mc2.x = 4;
  65.             mc2.y = 5;
  66.             mc2.z = 6;
  67.  
  68.             mc1 = mc2; // Copy
  69.             mc2.x = 10;
  70.             mc2.y = 11;
  71.             mc2.z = 12;
  72.  
  73.             System.Console.WriteLine(mc1.x);
  74.             System.Console.WriteLine(mc1.y);
  75.             System.Console.WriteLine(mc1.z);
  76.             */
  77.  
  78.             // MyClass1 mc1 = new MyClass2(); // ERROR
  79.             // MyClass2 mc2 = new MyClass1(); // ERROR
  80.         }
  81.  
  82.         // MyClass is reference type
  83.         class MyClass1
  84.         {
  85.             public int x;
  86.             public int y, z;
  87.         }
  88.         class MyClass2
  89.         {
  90.             public int x;
  91.             public int y, z;
  92.         }
  93.  
  94.         // MyStruct is value type
  95.         struct MyStruct
  96.         {
  97.             public int x;
  98.             public int y, z;
  99.         }
  100.     }
  101. }
Add Comment
Please, Sign In to add comment