Advertisement
wingman007

ITMOMMIIT2023Lections

Nov 6th, 2023
658
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 17.75 KB | None | 0 0
  1. using System.Globalization;
  2. using System.Net.NetworkInformation;
  3. using System.Text;
  4.  
  5. class Progarm
  6. {
  7.     static void Main()
  8.     {
  9.         // Greet();
  10.         // See https://aka.ms/new-console-template for more information
  11.         // 1. Hello World
  12.         Console.WriteLine("Hello, World!");
  13.  
  14.         // Shortcuts Ctrl+. | Ctrl+r,r | cw \t\t | Ctrl+k,d | Ctrl+k,c | Ctrl+k,u
  15.         // 2. Primitive data types, variables, literals
  16.         byte myByte1 = 1;
  17.         byte myByte2 = 7;
  18.  
  19.         sbyte mySByte1 = -1;
  20.  
  21.         Console.WriteLine(myByte1 + myByte2);
  22.  
  23.  
  24.         // I. Types have: name (e.g. int), size, default value
  25.         // II. Variables have: name (A-Za-z_0-9 all utf-8, can't start with 0-9, can't be a keyword), type, value
  26.         // built-in types:  
  27.         //2.1. integer (default = 0)
  28.         byte myByte = 23; // unsigned 8-bis (0 to 255) default = 0
  29.         sbyte mySByte = -128; // signed 8-bit (-128 to 127) default = 0
  30.  
  31.         short myShort = -1000; // signed 16-bit (-32,768 to 32,767) default = 0
  32.         ushort myUshort = 2000;  // unsigned 16-bit (0 to 65,535) default = 0
  33.  
  34.         int myVar = 4; // signed 32-bit (-2,147,483,648 to 2,147,483,647)
  35.         int myVar2 = 5; // signed 32-bit (-2,147,483,648 to 2,147,483,647)
  36.         uint myUint = 12000U; // unsigned 32-bit (0 to 4, 294, 967, 295)
  37.  
  38.         int sum = myVar + myVar2; // signed 32-bit (-2,147,483,648 to 2,147,483,647)
  39.  
  40.         sum = 0xA8F1; // hexadecimal literal
  41.         sum = 0XA8F1; // hexadecimal literal
  42.  
  43.         // Greet();
  44.  
  45.         long myLong = 42432L;// signed 64-bit (-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807)
  46.         ulong myUlong = 23423423U; // unsigned 64-bit (0 to 18,446,744,073,709,551,615)
  47.         ulong maxIntValue = UInt64.MaxValue;
  48.         Console.WriteLine(maxIntValue); // 18446744073709551615
  49.  
  50.         // 2.2. Real (default 0.0 for F/f D/d M/m)
  51.         float myFloat = 4.566F; // signed 32-bit (±1.5e-45 to ±3.4e38) up to 7 symbols/digits
  52.         myFloat = 67.8E35f; // litteral with "E/e"
  53.  
  54.         double myDouble = 34.56d; // signed 64-bit (±5.0e-324 to ±1.7e+308) up to 15-16 symbols/digits
  55.         myDouble = -3.4e-10;
  56.  
  57.         decimal myDecimal = 23.45M; // signed 128-bit (±1.0e-28 to ±7.9e28) precission 28-29 symbols/digits, closest to 0 ±1.0e-28, decimal floating-point arithmetic
  58.  
  59.  
  60.         // Declare some variables
  61.         float floatPI = 3.141592653589793238f;
  62.         double doublePI = 3.141592653589793238;
  63.         decimal decimalPI = 3.14159265358979323846m;
  64.  
  65.         Console.WriteLine("Float PI is: " + floatPI); // Float PI is: 3.141593 only 7 digits
  66.         Console.WriteLine("Double PI is: " + doublePI); // Double PI is: 3.14159265358979  16 digits
  67.         Console.WriteLine(decimalPI); // 3.14159265358979323846
  68.  
  69.         // 2.3. Char
  70.         char myFirstLetter = 'S';
  71.         Console.WriteLine((int)myFirstLetter);
  72.  
  73.         char symbol = (char)78;
  74.         Console.WriteLine(symbol);
  75.         char myChar = '\u0065';
  76.         Console.WriteLine(myChar);
  77.  
  78.         myChar = '\uffff';
  79.         Console.WriteLine(myChar);
  80.  
  81.         myChar = '\'';
  82.  
  83.         // escaping
  84.         char myEscape = '\n'; // \n \t \r \' \\ \" \uXXXX
  85.  
  86.         // 2.4. String (default null) Reference, value in the heap. String.Compare(string1, string2) > 0 if they have to switch
  87.         string myName = "Stoyan Cheresharov";
  88.  
  89.         // 2.5. Bool (default false)
  90.         bool myBool = true; // false | true
  91.  
  92.  
  93.         Object myObject = 2;
  94.         myObject = "Stoyan";
  95.  
  96.  
  97.         // 3.
  98.         int a = 5;
  99.         int b = 4;
  100.         Console.WriteLine(a + b); // 9
  101.         Console.WriteLine(a + b++); // 9
  102.         Console.WriteLine(a + b); // 10
  103.         Console.WriteLine(a + (++b)); // 11
  104.         Console.WriteLine(a + b); // 11
  105.         Console.WriteLine(14 / a); // 2
  106.         Console.WriteLine(14 % a); // 4
  107.  
  108.         // 3.1. Arithmetic operators
  109.         a = 11;
  110.         b = 2;
  111.         // Arithmetic operators
  112.         Console.WriteLine(a + b);
  113.         Console.WriteLine(a - b);
  114.         Console.WriteLine(a / b);
  115.         Console.WriteLine(a * b);
  116.         Console.WriteLine(a++);
  117.         Console.WriteLine(a);
  118.         Console.WriteLine(++a);
  119.         Console.WriteLine(a % b);
  120.         Console.WriteLine(--a);
  121.         Console.WriteLine(a--);
  122.  
  123.         //3.2. For comparison
  124.         Console.WriteLine(a > b);
  125.         Console.WriteLine(a < b);
  126.         Console.WriteLine(a >= b);
  127.         Console.WriteLine(a <= b);
  128.         Console.WriteLine(a == b);
  129.         Console.WriteLine(a != b);
  130.  
  131.         //3.3. Logical
  132.         bool x = true;
  133.         bool y = false;
  134.  
  135.         Console.WriteLine(x && y);
  136.         Console.WriteLine(x || y);
  137.         Console.WriteLine(x ^ y);
  138.         Console.WriteLine(!x);
  139.  
  140.         //&&
  141.         //x   y   z
  142.         //0   0   0
  143.         //1   0   0
  144.         //0   1   0
  145.         //1   1   1
  146.  
  147.         // ||
  148.         //x   y   z
  149.         //0   0   0
  150.         //1   0   1
  151.         //0   1   1
  152.         //1   1   1
  153.  
  154.         // ^
  155.         //x   y   z
  156.         //0   0   0
  157.         //1   0   1
  158.         //0   1   1
  159.         //1   1   0
  160.  
  161.         // !
  162.         //x z
  163.         //0 1
  164.         //1 0
  165.  
  166.         ////3.4. for asignments
  167.         //a += 3; // a = a + 3;
  168.  
  169.         ////3.5. Bitwise operators
  170.         //Console.WriteLine(1 << 1);
  171.         //Console.WriteLine(2 >> 1);
  172.         //Console.WriteLine(1 | 2);
  173.         //Console.WriteLine(1 & 2);
  174.         //Console.WriteLine(1 ^ 3);// 2
  175.  
  176.  
  177.         //// 3.6. trinary
  178.         //int c = (a > b) ? a : b;
  179.  
  180.         //if (a > b)
  181.         //{
  182.         //    c = a;
  183.         //}
  184.         //else
  185.         //{
  186.         //    c = b;
  187.         //}
  188.  
  189.         ////int? a1 = null;
  190.         ////int? b1 = 6;
  191.         //// a1 = null;
  192.         ////int? z = a1 ?? b1;
  193.  
  194.  
  195.         /*
  196.                 // 4. Console
  197.                 Console.OutputEncoding = Encoding.UTF8;
  198.                 Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("de-DE");
  199.  
  200.                 Console.Write("Stoyan ");
  201.                 Console.Write("Cheresharov");
  202.                 Console.WriteLine("My name is Desi. I am {0} years old. my favorite number is {1}", 10, 3);
  203.                 Console.WriteLine("{0,10:C2} I will continue", 1234);
  204.  
  205.                 // Formatting Numbers
  206.                 // Standard Formatting Symbols C, D, E, F, N, P, X
  207.                 Console.WriteLine("{0:C2}", 123.456); //Output: 123,46 лв.
  208.                 Console.WriteLine("{0:D6}", -1234); //Output: -001234
  209.                 Console.WriteLine("{0:E2}", 123); //Output: 1,23Е+002
  210.                 Console.WriteLine("{0:F2}", -123.456); //Output: -123,46
  211.                 Console.WriteLine("{0:N2}", 1234567.8); //Output: 1 234 567,80
  212.                 Console.WriteLine("{0:P}", 0.456); //Output: 45,60 %
  213.                 Console.WriteLine("{0:X}", 254); //Output: FE
  214.  
  215.                 // Custom Formatting Symbols 0000, ###, %, E0 Е+0 Е-0
  216.                 Console.WriteLine("{0:0.00}", 1); //Output: 1,00
  217.                 Console.WriteLine("{0:#.##}", 0.234); //Output: ,23
  218.                 Console.WriteLine("{0:#####}", 12345.67); //Output: 12346
  219.                 Console.WriteLine("{0:(0#) ### ## ##}", 29342525); //Output: (02) 934 25 25
  220.                 Console.WriteLine("{0:%##}", 0.234);//Output: %23
  221.  
  222.                 //Console.ForegroundColor = ConsoleColor.DarkYellow;
  223.                 //Console.BackgroundColor = ConsoleColor.DarkBlue;
  224.                 Console.Clear();
  225.                 // Standard Formatting Symbols for DateTime
  226.                 DateTime d = DateTime.Now;
  227.  
  228.                 Console.WriteLine("{0:d}", d); // d D
  229.  
  230.                 //Console.SetCursorPosition(5, 10); // left top
  231.                 Console.WriteLine("Това е кирилица: ☺");
  232.  
  233.                 // char unicorn = '\u1F984'; ???
  234.  
  235.                 Console.Write("Please enter your age: ");
  236.  
  237.                 int age = int.Parse(Console.ReadLine());
  238.  
  239.                 string name = "Stoyan";
  240.  
  241.                 char firstLetter = name[0];
  242.  
  243.                 int number = 312321;
  244.                 string numberString = number.ToString();
  245.                 Console.WriteLine(numberString[1]);
  246.  
  247.                 // 5. Conditional Logic
  248.                 int secondNumber = 3;
  249.                 int firstNumber = 2;
  250.                 if (secondNumber > firstNumber)
  251.                 {
  252.                     Console.WriteLine("secondNumber > firstNumber");
  253.                 }
  254.  
  255.                 if (true)
  256.                 {
  257.                     Console.WriteLine("secondNumber > firstNumber");
  258.                 }
  259.                 else
  260.                 {
  261.                     Console.WriteLine("secondNumber > firstNumber");
  262.                 }
  263.  
  264.                 int myAge = 12;
  265.  
  266.                 if (myAge < 3)
  267.                 {
  268.                     Console.WriteLine("You are a baby!");
  269.                 }
  270.                 else if (3 <= myAge && myAge < 12)
  271.                 {
  272.                     Console.WriteLine("You are a kid!");
  273.                 }
  274.                 else if (12 <= myAge && myAge < 18)
  275.                 {
  276.                     Console.WriteLine("You are a teenager!");
  277.                 }
  278.                 else if (18 <= myAge && myAge < 30)
  279.                 {
  280.                     Console.WriteLine("You are in your golden age!");
  281.                 }
  282.                 else
  283.                 {
  284.                     Console.WriteLine("You are an adult");
  285.                 }
  286.  
  287.  
  288.                 char firtsLetter = 'S';
  289.                 switch (firtsLetter)
  290.                 {
  291.                     case 'A':
  292.                     case 'S':
  293.                         Console.WriteLine("Your first letter tells me you are a lucky man!");
  294.                         break;
  295.                     case 'V':
  296.                         Console.WriteLine("You are victorious!");
  297.                         break;
  298.                     default:
  299.                         Console.WriteLine("I don't know?");
  300.                         break;
  301.                 }
  302.  
  303.                 // 6. loops
  304.                 int i = 0;
  305.                 while (i < 100)
  306.                 {
  307.                     Console.WriteLine(i);
  308.                     i++;
  309.                 }
  310.  
  311.                 int number1 = 0;
  312.                 do
  313.                 {
  314.                     Console.Write("Please, enter a number between 0 and 10:");
  315.                     number1 = int.Parse(Console.ReadLine());
  316.  
  317.                 } while (number1 < 0 || number1 > 10);
  318.  
  319.                 for (i = 0; i < 100; i++)
  320.                 {
  321.                     Console.WriteLine(i);
  322.                 }
  323.  
  324.                 int[] myArray = { 1, 2, 3,};
  325.                 foreach (var item in myArray)
  326.                 {
  327.                     Console.WriteLine(item);
  328.                 }
  329.  
  330.                 Console.Write("Please, enter a character: ");
  331.                 int myChar1 = Console.Read();
  332.                 Console.WriteLine(myChar1);
  333.  
  334.                 // int lucky = 1235;
  335.                 int a1, a2, a3, a4;
  336.  
  337.                 for (int lucky = 0; lucky <= 9999; lucky++)
  338.                 {
  339.                     a1 = lucky / 1000;
  340.                     a2 = (lucky / 100) % 10;
  341.                     a3 = (lucky / 10) % 10;
  342.                     a4 = lucky % 10;
  343.  
  344.                     if (a1 + a2 == a3 + a4)
  345.                     {
  346.                         Console.WriteLine(lucky);
  347.                     }
  348.                 }
  349.         */
  350.         Console.Clear();
  351.         // 7.
  352.         int[] ints = { 212, 22, 3, 4 };
  353.         ints[0] = 34;
  354.         Console.WriteLine(ints[0]);
  355.  
  356.         // 7.1.
  357.         int[] ints1 = new int[3];
  358.         ints1[1] = 4;
  359.  
  360.         // 7.2.
  361.         int[] ints2 = new int[3] { 32, 45, 67 };
  362.  
  363.         int lastElement = ints2[ints2.Length - 1];
  364.  
  365.         for (int i = 0; i < ints2.Length; i++)
  366.         {
  367.             Console.WriteLine(ints2[i]);
  368.         }
  369.  
  370.         int[,] matrix =
  371.         {
  372.             {32, 34, 45 },
  373.             { 56, 54, 34},
  374.             { 543, 34, 43}
  375.         };
  376.  
  377.         int[][] jagged = {
  378.             new int[] { 32, 45, 67},
  379.             new int[] {6456, 5435, 54345, 545}
  380.         };
  381.  
  382.         Console.WriteLine(jagged[1][1]);
  383.  
  384.         List<int> myList = new List<int>();
  385.         myList.Add(23);
  386.  
  387.         Dictionary<string, string> myDictionary = new Dictionary<string, string>();
  388.  
  389.         myDictionary.Add("щастлив", "happy");
  390.  
  391.         Console.WriteLine(myDictionary["щастлив"]);
  392.  
  393.         var tugay = "String";
  394.  
  395.         // var myInput = int.Parse(Console.ReadLine());
  396.  
  397.         foreach (var item in myList)
  398.         {
  399.             Console.WriteLine(item);
  400.         }
  401.  
  402.         string[] places = { "София", "пловдив" };
  403.  
  404.         int counter = 0;
  405.         for (int i = 0; i < places.Length; i++)
  406.         {
  407.             if (char.IsUpper(places[i][0]))
  408.             {
  409.                 Console.WriteLine(places[i]);
  410.                 counter++;
  411.             }
  412.         }
  413.  
  414.         Console.WriteLine("The cities with capital Letter are {0}", counter);
  415.  
  416.         Console.WriteLine("2093 to BIN {0}.", Convert.ToString(2093, 2));
  417.         Console.WriteLine("2093 to OCT {0}.", Convert.ToString(2093, 8));
  418.         Console.WriteLine("2093 to HEX {0}.", Convert.ToString(2093, 16));
  419.         Console.WriteLine("2093 In a number system with base/radix = 5 {0}.",
  420.             Convert.ToString(2093, 2));
  421.  
  422.         Console.WriteLine();
  423.  
  424.         for (int i = ints2.Length - 1; i >= 0; i--)
  425.         {
  426.             Console.WriteLine(ints2[i]);
  427.         }
  428.  
  429.  
  430.         //Console.WriteLine(DateTime.Now);
  431.  
  432.         //int x1 = 0, y1 = 0;
  433.  
  434.         //while (true)
  435.         //{
  436.         //    Console.Clear();
  437.         //    Console.SetCursorPosition(x1, y1);
  438.         //    Console.WriteLine(DateTime.Now);
  439.         //    Thread.Sleep(10);
  440.         //    x1++;
  441.         //    y1++;
  442.         //}
  443.  
  444.  
  445.         // 8.
  446.  
  447.         // IV
  448.         //VI
  449.  
  450.         //44(10)
  451.  
  452.         //4 * 10 ^ 1 + 4 * 10 ^ 0 = 40 + 4
  453.  
  454.         //44(8)
  455.  
  456.         //4 * 8 ^ 1 + 4 * 8 ^ 0 = 32 + 4 = 36
  457.  
  458.         //44(5)
  459.         //4 * 5 ^ 1 + 4 * 5 ^ 0 = 20 + 4 = 24
  460.  
  461.         //44
  462.  
  463.         //44 : 2 = 22 | 0
  464.         //22 : 2 = 11 | 0
  465.         //11 : 2 = 5 | 1
  466.         //5 : 2 = 2 | 1
  467.         //2 : 2 = 1 | 0
  468.         //            1
  469.  
  470.         //101100(2) = 44(10)
  471.  
  472.  
  473.         //0010 1100
  474.  
  475.         //2C
  476.  
  477.         //8421
  478.  
  479.         //101 100
  480.         //5    4
  481.  
  482.         //54()
  483.  
  484.         //23.45
  485.  
  486.         //23 : 2 = 11 | 1
  487.         //11 : 2 = 5 | 1
  488.         //5 : 2 = 2 | 1
  489.         //2 : 2 = 1 | 0
  490.  
  491.         //        1
  492.  
  493.         //10111.011
  494.  
  495.         //1.0111011 * 2 ^ 4
  496.  
  497.         //.45 * 2 = 0.9 | 0
  498.         //0.9 * 2 = 0.8 | 1
  499.         //0.8 * 2 = 0.6 | 1
  500.  
  501.         //123.56 => 1,23.56 * 10 ^ 2
  502.  
  503.  
  504.         //number = 346
  505.         //(r ^ n - 1) - number
  506.  
  507.         //(10 ^ 3 - 1) - 346 =
  508.         //999
  509.         //-
  510.         //346
  511.         //---- -
  512.         //653
  513.  
  514.         //9999999999
  515.         //-
  516.         //4332423532
  517.         //----------------
  518.         //5667...
  519.  
  520.  
  521.         //1111111111111
  522.         //-
  523.         //1010101111111
  524.         //------------------
  525.         //0101010000000
  526.  
  527.         //(r ^ n - 1) - number
  528.         //(r ^ n) - number
  529.  
  530.  
  531.         //7 - 3 = 4
  532.  
  533.         //7 + 7 = 1 | 4
  534.  
  535.  
  536.  
  537.  
  538.  
  539.  
  540.         /*
  541.  
  542.         // ------ in a nutshell -----
  543.  
  544.         //a += 3; // a = a + 3;
  545.  
  546.         //// essentials
  547.         //// 4.
  548.         //Console.WriteLine();
  549.         //string name = Console.ReadLine();
  550.         //double n = double.Parse(Console.ReadLine());
  551.  
  552.         //// 5. Conditional logic
  553.         //// 5.1.
  554.         //if (a > 5)
  555.         //{
  556.         //    Console.WriteLine("a > 5");
  557.         //}
  558.  
  559.         //if (a > 5)
  560.         //{
  561.         //    Console.WriteLine("a > 5");
  562.         //}
  563.         //else
  564.         //{
  565.         //    Console.WriteLine("a < 5");
  566.         //}
  567.  
  568.         //Console.WriteLine("Please enter your age: ");
  569.         //int age = int.Parse(Console.ReadLine());
  570.         //if (age > 0 && age <= 3)
  571.         //{
  572.         //    Console.WriteLine("You are a baby");
  573.         //}
  574.         //else if (age > 3 && age <= 12)
  575.         //{
  576.         //    Console.WriteLine("You are a kid");
  577.         //}
  578.         //else if (age > 12 && age <= 18)
  579.         //{
  580.         //    Console.WriteLine("You are a teenager");
  581.         //}
  582.         //else
  583.         //{
  584.         //    Console.WriteLine("You are an adult");
  585.         //}
  586.  
  587.  
  588.         //char firstLetter = Char.Parse(Console.ReadLine());
  589.         //switch (firstLetter)
  590.         //{
  591.         //    case 'A':
  592.         //    case 'N':
  593.         //        Console.WriteLine("Maybe your name is Nilyay");
  594.         //        break;
  595.         //    default:
  596.         //        Console.WriteLine("I don't know");
  597.         //        break;
  598.         //}
  599.  
  600.  
  601.         //// 6. Loops
  602.  
  603.         //int i = 0;
  604.         //while (i < 100)
  605.         //{
  606.         //    Console.WriteLine(i);
  607.         //    i++;
  608.         //}
  609.  
  610.  
  611.         //do
  612.         //{
  613.         //    Console.WriteLine("Please enter your age: ");
  614.         //    age = int.Parse(Console.ReadLine());
  615.         //} while (age < 0 && age > 120);
  616.  
  617.  
  618.  
  619.         //for (i = 0; i < 100; i++)
  620.         //{
  621.         //    Console.WriteLine(i);
  622.         //}
  623.         Greet("Nilyay");
  624.         int[] ages = new int[10];
  625.         ages[0] = 18;
  626.         ages[5] = 17;
  627.  
  628.         foreach (int item in ages)
  629.         {
  630.             Console.WriteLine(item);
  631.         }
  632.  
  633.         Greet("Magi");
  634.  
  635.  
  636.         int number = 5698;
  637.         int a1 = number / 1000;
  638.         int a2 = (number / 100) % 10;
  639.         int a3 = (number / 10) % 10;
  640.         int a4 = number % 10;
  641.  
  642.         Console.WriteLine("The number in reverse is {0}{1}{2}{3}", a4, a3, a2, a1);
  643.     }
  644.  
  645.     static void Greet(string name = "Megan")
  646.     {
  647.         Console.WriteLine("Hello" + name);
  648.     }
  649.  
  650.     static int CalculateSum(int a, int b)
  651.     {
  652.         return a + b;
  653.     }
  654.  
  655.     */
  656.  
  657.  
  658.     }
  659. }
  660.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement