Advertisement
wingman007

2018_IntroC#CheatsheetPartTimeArraysBinaryMethodsRecursion

Sep 16th, 2018
828
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 23.63 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading;
  7. using System.Threading.Tasks;
  8.  
  9. namespace MyAppSTD2018
  10. {
  11.     class Program
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.             // Shortcuts Ctrl+. | Ctrl+r,r | cw \t\t | Ctrl+k,d | Ctrl+k,c | Ctrl+k,u
  16.             // I. Types have: name (e.g. int), size, default value
  17.             // 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
  18.             // built-in types:  
  19.             //1. integer (default = 0)
  20.             byte myByte = 23; // unsigned 8-bis (0 to 255) default = 0
  21.             sbyte mySByte = -128; // signed 8-bit (-128 to 127) default = 0
  22.  
  23.             short myShort = -1000; // signed 16-bit (-32,768 to 32,767)
  24.             ushort myUshort = 2000;  // unsigned 16-bit (0 to 65,535)
  25.  
  26.             int myVar = 4; // signed 32-bit (-2,147,483,648 to 2,147,483,647)
  27.             int myVar2 = 5; // signed 32-bit (-2,147,483,648 to 2,147,483,647)
  28.             int sum = myVar + myVar2; // signed 32-bit (-2,147,483,648 to 2,147,483,647)
  29.             uint myUint = 12000U; // unsigned 32-bit (0 to 4, 294, 967, 295)
  30.             sum = 0xA8F1; // hexadecimal literal
  31.             sum = 0XA8F1; // hexadecimal literal
  32.  
  33.             long myLong = 42432L;// signed 64-bit (-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807)
  34.             ulong myUlong = 23423423U; // unsigned 64-bit (0 to 18,446,744,073,709,551,615)
  35.             ulong maxIntValue = UInt64.MaxValue;
  36.             Console.WriteLine(maxIntValue); // 18446744073709551615
  37.  
  38.             // Check if there is overflow and throw an exception
  39.             //checked
  40.             //{
  41.             //    int maxInt = int.MaxValue;
  42.             //    maxInt = maxInt + 1;
  43.             //    Console.WriteLine(maxInt);
  44.             //}
  45.             // if there is no check we will get wrong result -2147483648
  46.            // BigInteger myBigInt = 3213213; // No limits
  47.  
  48.             // 2. Real (default 0.0 for F/f D/d M/m)
  49.             float myFloat = 4.566F; // signed 32-bit (±1.5e-45 to ±3.4e38) up to 7 symbols/digits
  50.             myFloat = 67.8E35f; // litteral with "E/e"
  51.             double myDouble = 34.56d; // signed 64-bit (±5.0e-324 to ±1.7e+308) up to 15-16 symbols/digits
  52.             myDouble = -3.4e-10d;
  53.             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
  54.  
  55.             // Declare some variables
  56.             float floatPI = 3.141592653589793238f;
  57.             double doublePI = 3.141592653589793238;
  58.             // Print the results on the console
  59.             Console.WriteLine("Float PI is: " + floatPI); // Float PI is: 3.141593 only 7 digits
  60.             Console.WriteLine("Double PI is: " + doublePI); // Double PI is: 3.14159265358979  16 digits
  61.             decimal decimalPI = 3.14159265358979323846m;
  62.             Console.WriteLine(decimalPI); // 3.14159265358979323846
  63.  
  64.             // 3. Char
  65.             char myFirstLetter = 'S';
  66.             Console.WriteLine((int)myFirstLetter);
  67.             char symbol = (char)5;
  68.             char myChar = '\u0065';
  69.             Console.WriteLine(myChar);
  70.             myChar = '\uffff';
  71.             Console.WriteLine(myChar);
  72.             // escaping
  73.             char myEscape = '\n'; // \n \t \r \' \\ \" \uXXXX
  74.  
  75.             // 4. String (default null) Reference, value in the heap
  76.             string myName = "Stoyan Cheresharov";
  77.             string path = @"D:\CamtasiaVideos"; // instead of D:\\CamtasiaVideos
  78.  
  79.             Console.WriteLine($"The Path is {path}");
  80.  
  81.             //StringBuilder text = new StringBuilder();
  82.             //foreach (char symbol in list)
  83.             // {
  84.             //    text.Append(symbol);
  85.             //}
  86.  
  87.             // 5. Bool (default false)
  88.             bool myBool = true; // false | true
  89.  
  90.             // 6. Object (default null) Reference, value in the heap
  91.             Object myObject = 3;
  92.  
  93.             Nullable<int> i1 = null;
  94.             int? i2 = i1;
  95.  
  96.             // typeof()
  97.             // Console.WriteLine(typeof(i1)); // error
  98.             // Used to obtain the System.Type object for a type. A typeof expression takes the following form:
  99.             System.Type type = typeof(int);
  100.             int i = 0;
  101.             type = i.GetType();
  102.             Console.WriteLine(type);
  103.  
  104.             // sizeof - Used to obtain the size in bytes for an unmanaged type.
  105.             Console.WriteLine(sizeof(sbyte)); // 1
  106.             // Unmanaged types include:
  107.             // The simple types that are listed in the following table:
  108.             // Expression Constant value
  109.             //sizeof(sbyte)   1
  110.             //sizeof(byte)    1
  111.             //sizeof(short)   2
  112.             //sizeof(ushort)  2
  113.             //sizeof(int) 4
  114.             //sizeof(uint)    4
  115.             //sizeof(long)    8
  116.             //sizeof(ulong)   8
  117.             //sizeof(char)    2(Unicode)
  118.             //sizeof(float)   4
  119.             //sizeof(double)  8
  120.             //sizeof(decimal) 16
  121.             //sizeof(bool)    1
  122.  
  123.             Console.WriteLine("Hello World! The sum is " + sum);
  124.             Console.WriteLine("-----------------------");
  125.             Console.WriteLine((char)65);
  126.             Console.WriteLine((int)'D');
  127.             Console.WriteLine('\u0065');
  128.             int? myVanya = null;
  129.             Console.WriteLine("Vanya is " + myVanya.ToString() + " years old!");
  130.             Console.WriteLine(sizeof(long));
  131.             int myDesiInt = 10;
  132.             // double myDesiDouble = 1.2;
  133.             int myDesiDouble = 3;
  134.             Console.WriteLine("Desi " + ((double)myDesiInt / myDesiDouble));
  135.             // Console.WriteLine("Desi " + ((myDesiInt / myDesiDouble));
  136.  
  137.             // Ctrl+r,r - refactoring/replace a name/string
  138.             // Not possible
  139.             //int? implicitConvertInt = 0;
  140.             //if (implicitConvertInt) { // Can not implicitly convert type int to bool
  141.             //}
  142.             //Object implicitConverToObj = null;
  143.             //if (implicitConverToObj) { // Can not implicitly convert type Obj to bool
  144.             //}
  145.  
  146.             myDesiInt++;
  147.             Console.WriteLine(myDesiInt);
  148.             Console.WriteLine((myDesiInt > 18) ? "You are an adult" : "You are young");
  149.             byte myTest = 1;
  150.             Console.WriteLine(myTest);
  151.             Console.WriteLine(myTest << 1);
  152.             Console.WriteLine(myTest << 2);
  153.             myTest <<= 2;
  154.             Console.WriteLine(myTest);
  155.             byte myGeorgi = 8;
  156.             Console.WriteLine(myTest | myGeorgi);
  157.  
  158.             int squarePerimeter = 17;
  159.             double squareSide = squarePerimeter / 4.0;
  160.             double squareArea = squareSide * squareSide;
  161.             Console.WriteLine(squareSide); // 4.25
  162.             Console.WriteLine(squareArea); // 18.0625
  163.             int a = 5;
  164.             int b = 4;
  165.             Console.WriteLine(a + b); // 9
  166.             Console.WriteLine(a + b++); // 9
  167.             Console.WriteLine(a + b); // 10
  168.             Console.WriteLine(a + (++b)); // 11
  169.             Console.WriteLine(a + b); // 11
  170.             Console.WriteLine(14 / a); // 2
  171.             Console.WriteLine(14 % a); // 4
  172.  
  173.  
  174.             a = 11;
  175.             b = 2;
  176.             // Arithmetic operators
  177.             Console.WriteLine(a + b);
  178.             Console.WriteLine(a - b);
  179.             Console.WriteLine(a / b);
  180.             Console.WriteLine(a * b);
  181.             Console.WriteLine(a++);
  182.             Console.WriteLine(a);
  183.             Console.WriteLine(++a);
  184.             Console.WriteLine(a % b);
  185.             Console.WriteLine(--a);
  186.             Console.WriteLine(a--);
  187.  
  188.             // For comparison
  189.             Console.WriteLine(a > b);
  190.             Console.WriteLine(a < b);
  191.             Console.WriteLine(a >= b);
  192.             Console.WriteLine(a <= b);
  193.             Console.WriteLine(a == b);
  194.             Console.WriteLine(a != b);
  195.  
  196.             // Logical
  197.             bool x = true;
  198.             bool y = false;
  199.  
  200.             Console.WriteLine(x && y);
  201.             Console.WriteLine(x || y);
  202.             Console.WriteLine(x ^ y);
  203.             Console.WriteLine(!x);
  204.  
  205.             // for asignments
  206.             a += 3; // a = a + 3;
  207.  
  208.             // Bitwise operators
  209.             Console.WriteLine(1 << 1);
  210.             Console.WriteLine(2 >> 1);
  211.             Console.WriteLine(1 | 2);
  212.             Console.WriteLine(1 & 2);
  213.             Console.WriteLine(1 ^ 3);// 2
  214.  
  215.             // int? a = 5;
  216.             // int? b = 6
  217.             // a = null;
  218.             // int? z = a ?? b;
  219.  
  220.             // long d = 3214321342134231443;
  221.  
  222.             // int i = checked((int)d); // System.OverflowException
  223.  
  224.             int one = 1;
  225.             int zero = 0;
  226.             // Console.WriteLine(one / zero); // DivideByZeroException
  227.             double dMinusOne = -1.0;
  228.             double dZero = 0.0;
  229.             Console.WriteLine(dMinusOne / zero); // -Infinity
  230.             Console.WriteLine(one / dZero); // Infinity
  231.             Console.Clear();
  232.             Console.Write("Stoyan ");
  233.             Console.Write("Cheresharov \n\r");
  234.             Console.WriteLine("My name is Desi. I am {0} years old. my favorite number is {1}", myDesiInt, 3);
  235.             Console.WriteLine("| {0,10:######} |", 12);
  236.  
  237.             // Formatting Numbers
  238.             // Standard Formatting Symbols C, D, E, F, N, P, X
  239.             Console.WriteLine("{0:C2}", 123.456); //Output: 123,46 лв.
  240.             Console.WriteLine("{0:D6}", -1234); //Output: -001234
  241.             Console.WriteLine("{0:E2}", 123); //Output: 1,23Е+002
  242.             Console.WriteLine("{0:F2}", -123.456); //Output: -123,46
  243.             Console.WriteLine("{0:N2}", 1234567.8); //Output: 1 234 567,80
  244.             Console.WriteLine("{0:P}", 0.456); //Output: 45,60 %
  245.             Console.WriteLine("{0:X}", 254); //Output: FE
  246.  
  247.             // Custom Formatting Symbols 0000, ###, %, E0 Е+0 Е-0
  248.             Console.WriteLine("{0:0.00}", 1); //Output: 1,00
  249.             Console.WriteLine("{0:#.##}", 0.234); //Output: ,23
  250.             Console.WriteLine("{0:#####}", 12345.67); //Output: 12346
  251.             Console.WriteLine("{0:(0#) ### ## ##}", 29342525); //Output: (02) 934 25 25
  252.             Console.WriteLine("{0:%##}", 0.234);//Output: %23
  253.  
  254.             // Standard Formatting Symbols for DateTime
  255.             DateTime d = new DateTime(2018, 9, 14, 15, 30, 22);
  256.  
  257.             Console.WriteLine("{0:D}", d); // d D
  258.             Console.WriteLine("{0:t}", d); // t T
  259.             Console.WriteLine("{0:Y}", d); // y Y
  260.  
  261.             // Custom Formatting Symbols for DateTime d, dd, M, MM, yy, yyyy, hh, HH, m, mm, s, ss
  262.             Console.WriteLine("{0:dd/MM/yyyy HH:mm:ss}", d);
  263.             Console.WriteLine("{0:d.MM.yy г.}", d);
  264.             // return;
  265.             Console.Clear();
  266.             Thread.CurrentThread.CurrentCulture =
  267.             CultureInfo.GetCultureInfo("bg-Bg");
  268.  
  269.             Console.WriteLine("| {0,10:C} |", 120000.4532);
  270.             Console.Clear();
  271.  
  272.             // Reading from the console and parsing
  273.  
  274.             Console.Write("Please enter your age: ");
  275.             string inputVariable = Console.ReadLine();
  276.  
  277.             // Parsing strings to numbers
  278.             int age = int.Parse(inputVariable);
  279.             double ageInDouble;
  280.             double.TryParse(inputVariable, out ageInDouble);
  281.             Console.WriteLine(Convert.ToInt16(inputVariable));
  282.             Console.WriteLine(age + 10);
  283.  
  284.             // Read a character from the input with Read
  285.             //Console.Write("Please enter a character: ");
  286.             //int nextChar = Console.Read();
  287.             //Console.WriteLine(nextChar);
  288.             //Console.WriteLine((char)nextChar);
  289.             // return;
  290.  
  291.             // ReadKey
  292.             //Console.WriteLine("Please press ESC key to exit this endless loop");
  293.             //ConsoleKeyInfo cki;
  294.             //do {              
  295.             //    if (!Console.KeyAvailable)
  296.             //    {
  297.             //        Console.Clear();
  298.             //        Console.WriteLine("Please hit Esc");
  299.             //    }
  300.             //    cki = Console.ReadKey(true);
  301.             //    System.Threading.Thread.Sleep(50);
  302.             //} while(cki.Key != ConsoleKey.Escape);
  303.  
  304.  
  305.             Console.OutputEncoding = Encoding.UTF8;
  306.  
  307.             Console.ForegroundColor = ConsoleColor.Green;
  308.             // Console.BackgroundColor = ConsoleColor.Blue;
  309.             // To change the background color of the > console window as a whole, set the BackgroundColor property and call the Clear method.
  310.             // Console.BackgroundColor = ConsoleColor.Blue;
  311.             // Console.Clear();
  312.  
  313.             Console.SetCursorPosition(5, 10); // left top
  314.             Console.WriteLine("Това е кирилица: ☺");
  315.  
  316.             Thread.CurrentThread.CurrentCulture =
  317.             CultureInfo.GetCultureInfo("en-GB"); // UK doesn't work
  318.  
  319.             // Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
  320.  
  321.             Console.WriteLine("Your balance is {0, 30:C2}", 1234567.8904534);
  322.  
  323.             //for (int charCode = 0; charCode < 1000; i++)
  324.             //{
  325.             //    Console.WriteLine((char)i);
  326.             //}
  327.  
  328.             int secondNumber = 3;
  329.             int firstNumber = 2;
  330.             if (secondNumber > firstNumber)
  331.             {
  332.                 // int biggerNumber = secondNumber;
  333.                 Console.WriteLine(secondNumber);
  334.             }
  335.  
  336.             char ch = 'X';
  337.             if (ch == 'A' || ch == 'a')
  338.             {
  339.                 Console.WriteLine("Vowel [ei]");
  340.             }
  341.             else if (ch == 'E' || ch == 'e')
  342.             {
  343.                 Console.WriteLine("Vowel [i:]");
  344.             }
  345.             else if (ch == 'I' || ch == 'i')
  346.             {
  347.                 Console.WriteLine("Vowel [ai]");
  348.             }
  349.             else if (ch == 'O' || ch == 'o')
  350.             {
  351.                 Console.WriteLine("Vowel [ou]");
  352.             }
  353.             else if (ch == 'U' || ch == 'u')
  354.             {
  355.                 Console.WriteLine("Vowel [ju:]");
  356.             }
  357.             else
  358.             {
  359.                 Console.WriteLine("Consonant");
  360.             }
  361.  
  362.             //if (булев израз)
  363.             //{
  364.             //    тяло на условната конструкция;
  365.             //}
  366.             //else
  367.             //{
  368.             //    тяло на else-конструкция;
  369.             //}
  370.  
  371.             //switch (селектор)
  372.             //{
  373.             //    case целочислена - стойност - 1: конструкция; break;
  374.             //    case целочислена - стойност - 2: конструкция; break;
  375.             //    case целочислена - стойност - 3: конструкция; break;
  376.             //    case целочислена - стойност - 4: конструкция; break;
  377.             //    // …
  378.             //    default: конструкция; break;
  379.             //}
  380.  
  381.             //while (условие)
  382.             //{
  383.             //    тяло на цикъла;
  384.             //}
  385.  
  386.             // Initialize the counter
  387.             int counter = 0;
  388.             // Execute the loop body while the loop condition holds
  389.             while (counter <= 9)
  390.             {
  391.                 // Print the counter value
  392.                 Console.WriteLine("Number : " + counter);
  393.                 // Increment the counter
  394.                 counter++;
  395.             }
  396.  
  397.             //  n! = (n - 1)!*n
  398.             Console.Write("Please, enter a number: ");
  399.             int n = int.Parse(Console.ReadLine());
  400.             // "decimal" is the biggest type that can hold integer values
  401.             decimal factorial = 1;
  402.             // Perform an "infinite loop"
  403.             while (true)
  404.             {
  405.                 if (n <= 1)
  406.                 {
  407.                     break;
  408.                 }
  409.                 factorial *= n;
  410.                 n--;
  411.             }
  412.             Console.WriteLine("n! = " + factorial);
  413.  
  414.             int myDoTest = 0;
  415.             do
  416.             {
  417.                 Console.Write("Please enter a number betwen 0 and 5: ");
  418.                 myDoTest = int.Parse(Console.ReadLine());
  419.             } while (myDoTest > 5 || myDoTest < 0);
  420.  
  421.             //for (инициализация; условие; обновяване)
  422.             //{
  423.             //    тяло на цикъла;
  424.             //}
  425.  
  426.             for (int j = 0; j <= 10; j++)
  427.             {
  428.                 Console.Write(j + " ");
  429.             }
  430.  
  431.             int t = 0;
  432.             while (t < 10)
  433.             {
  434.                 // i++;
  435.                 // break;
  436.                 if (t % 2 == 0)
  437.                 {
  438.                     t++;
  439.                     continue;
  440.                 }
  441.                 Console.WriteLine("t = " + t);
  442.                 t++;
  443.             }
  444.  
  445.             int[] numbers = { 2, 3, 5, 7, 11, 13, 17, 19 };
  446.             foreach (int k in numbers)
  447.             {
  448.                 Console.Write(" " + k);
  449.             }
  450.             Console.WriteLine();
  451.  
  452.             String[] towns = { "Sofia", "Plovdiv", "Varna", "Bourgas" };
  453.             foreach (String town in towns)
  454.             {
  455.                 Console.Write(" " + town);
  456.             }
  457.  
  458.             int special = 34;
  459.             Console.WriteLine($"This is my variable {special}");
  460.  
  461.             Console.BackgroundColor = ConsoleColor.DarkBlue;
  462.             Console.Clear();
  463.             Console.ForegroundColor = ConsoleColor.Yellow;
  464.  
  465.             string[] students = new string[100];
  466.             students[0] = "Konstantin";
  467.             students[1] = "Angel";
  468.  
  469.             Console.WriteLine(students[0]);
  470.  
  471.             int[] myArray = { 1, 2, 3, 4, 5, 6 };
  472.             int[] myArray2 = new int[3] { 23, 45, 67 };
  473.  
  474.             string[] daysOfWeek =
  475.             {
  476.                 "Monday",
  477.                 "Tuesday",
  478.                 "Wednesday",
  479.                 "Thursday",
  480.                 "Friday",
  481.                 "Saturday",
  482.                 "Sunday"
  483.             };
  484.  
  485.             int[] array = new int[] { 1, 2, 3, 4, 5 };
  486.             Console.Write("Output: ");
  487.             for (int index = 0; index < array.Length; index++)
  488.             {
  489.                 // Doubling the number
  490.                 array[index] = 2 * array[index];
  491.                 // Print the number
  492.                 Console.Write(array[index] + " ");
  493.             }
  494.             // Output: 2 4 6 8 10
  495.  
  496.             //foreach (var item in collection)
  497.             //{
  498.             //    // Process the value here
  499.             //}
  500.  
  501.             int[,] matrix =
  502.             {
  503.                 {1, 2, 3, 4}, // row 0 values
  504.                 {5, 6, 7, 8}, // row 1 values
  505.             };
  506.             // The matrix size is 2 x 4 (2 rows, 4 cols)
  507.  
  508.             Console.WriteLine();
  509.             Console.WriteLine(matrix[0,3]); // 4
  510.  
  511.             Console.WriteLine(matrix.GetLength(0));
  512.             Console.WriteLine(matrix.GetLength(1));
  513.  
  514.             int[][] myJaggedArray = {
  515.                 new int[] {5, 7, 2},
  516.                 new int[] {10, 20, 40},
  517.                 new int[] {3, 25},
  518.                 new int[] { 1,2,3,4,5,6,78,9}
  519.             };
  520.  
  521.             int[][,] jaggedOfMulti = new int[2][,];
  522.  
  523.             // another way to declare jagged array
  524.             int[][] jaggedArray;
  525.             jaggedArray = new int[2][];
  526.             jaggedArray[0] = new int[5];
  527.             jaggedArray[1] = new int[3];
  528.  
  529.  
  530.  
  531.             // String number = "100";
  532.             // int fromBase = 16;
  533.             // int toBase = 10;
  534.  
  535.             // String result1 = Convert.ToString(Convert.ToInt32(number, fromBase), toBase);
  536.  
  537.            // result == "256"
  538.            // Console.WriteLine(result1);
  539.  
  540.  
  541.  
  542.             /*
  543.             // Convert to binary system
  544.             Console.Write("Please, enter a number to convert to binary: ");
  545.             // with 340282366920938000000000000000000000000
  546.             // System.OverflowException: Value was either too large or too small for an Int32.
  547.             int number2Convert = int.Parse(Console.ReadLine());
  548.             int[] binaryNumber = new int[128]; // the default value is 0
  549.             int digitCounter = 127;
  550.             while (number2Convert > 0 && digitCounter > 0)
  551.             {
  552.                 binaryNumber[digitCounter] = number2Convert % 2;
  553.                 digitCounter--;
  554.                 number2Convert /= 2;
  555.                 Console.WriteLine(number2Convert);
  556.             }
  557.             foreach (var digit in binaryNumber)
  558.             {
  559.                 Console.Write(digit);
  560.             }
  561.             Console.WriteLine();
  562.             Console.WriteLine(Math.Pow(2, 128)); // 3.40282366920938E+38
  563.             // Console.WriteLine("{0,10:N}", Math.Pow(2, 128)); // 340,282,366,920,938,000,000,000,000,000,000,000,000.00
  564.             // Console.WriteLine("{0,10:D}", Math.Pow(2, 128)); // Exception
  565.             Console.WriteLine("{0,10:F0}", Math.Pow(2, 128)); // 340282366920938000000000000000000000000
  566.  
  567.                 // https://stackoverflow.com/questions/2954962/convert-integer-to-binary-in-c-sharp
  568.                 int value = 8;
  569.                 string binary = Convert.ToString(value, 2);
  570.  
  571.                 // Convert from any classic base to any base in C#
  572.                
  573.                 String number = "100";
  574.                 int fromBase = 16;
  575.                 int toBase = 10;
  576.  
  577.                 String result = Convert.ToString(Convert.ToInt32(number, fromBase), toBase);
  578.  
  579.                 // result == "256"
  580.                 // Supported bases are 2, 8, 10 and 16
  581.  
  582.             */
  583.  
  584.             // Convert from decimal to binary system
  585.             //34 - > 100010 = 1 * 2 ^ 5 + 0 + 0 + 0 + 1 * 2 ^ 1 + 0 = 32 + 2 = 34
  586.  
  587.             //34 : 2 = 17  0
  588.             //17 : 2 = 8   1
  589.             //8 : 2 = 4    0
  590.             //4 : 2 = 2    0
  591.             //2 : 2 = 1    0
  592.             //             1
  593.  
  594.             //100010
  595.             //100010
  596.  
  597.             // 8| 4 | 2 | 1
  598.             // e.g. 12 is 8 + 4 then we put 1 in positions of 8 and 4 -> 1100
  599.  
  600.             // Convert form base 16 to base 2
  601.             //0010 | 1010 | 1010 | 1010 | 1111 | 1110 | 0001 | 1111 | 1111
  602.  
  603.             //2AAAFD1FF
  604.  
  605.  
  606.             // Method calls
  607.             string[] studentsTemp = new string[2];
  608.             InputNames(studentsTemp);
  609.             InputNames(studentsTemp, 5);
  610.             InputNames(studentsTemp, 3, 2, 3, 4, 5, 6, 2, 3, 6, 6);
  611.             InputNames(n: 6, names: studentsTemp);
  612.  
  613.             // Recursion
  614.             int factorial2 = 5;
  615.             Console.WriteLine("!{0} = {1}", factorial2, Factorial(factorial2));
  616.  
  617.  
  618.             // Standard Math functions
  619.             Console.WriteLine(Math.Cos(23));
  620.  
  621.             // every string can be used as array
  622.             string stoyanName = "Stoyan";
  623.             Console.WriteLine(stoyanName[0]); // S
  624.             // string functions - tyme the name of the variable and .
  625.             Console.WriteLine(stoyanName.IndexOf('t'));
  626.             // etc.
  627.         }
  628.  
  629.         // Method declaration and definition, default parameters, variable number of parameters
  630.         static void InputNames(string[] names, int n = 4, params int[] myExtraParams)
  631.         {
  632.             for (var i = 0; i < names.Length; i++)
  633.             {
  634.                 Console.Write("Please enter element number {0} :", i);
  635.                 names[i] = Console.ReadLine() + " Default Mark = " + n + " Final Mark" + ((myExtraParams.Length > 0) ? myExtraParams[i].ToString() : "0"); //
  636.                 Console.WriteLine(names[i]);
  637.             }
  638.         }
  639.  
  640.         // Recursion
  641.         // !n = !(n-1) * n
  642.         static int Factorial(int n)
  643.         {
  644.             if (n == 0) return 1;
  645.             return Factorial(n - 1) * n;
  646.         }
  647.     }
  648. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement