Advertisement
wingman007

2018_IntroC#PartTimeOperatorsConsoleIfFor

Sep 15th, 2018
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 13.31 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.             // I. Types have: name (e.g. int), size, default value
  16.             // 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
  17.             // built-in types:  
  18.             //1. integer (default = 0)
  19.             byte myByte = 23; // unsigned 8-bis (0 to 255) default = 0
  20.             sbyte mySByte = -128; // signed 8-bit (-128 to 127) default = 0
  21.  
  22.             short myShort = -1000; // signed 16-bit (-32,768 to 32,767)
  23.             ushort myUshort = 2000;  // unsigned 16-bit (0 to 65,535)
  24.  
  25.             int myVar = 4; // signed 32-bit (-2,147,483,648 to 2,147,483,647)
  26.             int myVar2 = 5; // signed 32-bit (-2,147,483,648 to 2,147,483,647)
  27.             int sum = myVar + myVar2; // signed 32-bit (-2,147,483,648 to 2,147,483,647)
  28.             uint myUint = 12000U; // unsigned 32-bit (0 to 4, 294, 967, 295)
  29.             sum = 0xA8F1; // hexadecimal literal
  30.             sum = 0XA8F1; // hexadecimal literal
  31.  
  32.             long myLong = 42432L;// signed 64-bit (-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807)
  33.             ulong myUlong = 23423423U; // unsigned 64-bit (0 to 18,446,744,073,709,551,615)
  34.             ulong maxIntValue = UInt64.MaxValue;
  35.             Console.WriteLine(maxIntValue); // 18446744073709551615
  36.  
  37.             // 2. Real (default 0.0 for F/f D/d M/m)
  38.             float myFloat = 4.566F; // signed 32-bit (±1.5e-45 to ±3.4e38) up to 7 symbols/digits
  39.             myFloat = 67.8E35f; // litteral with "E/e"
  40.             double myDouble = 34.56d; // signed 64-bit (±5.0e-324 to ±1.7e+308) up to 15-16 symbols/digits
  41.             myDouble = -3.4e-10d;
  42.             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
  43.  
  44.             // Declare some variables
  45.             float floatPI = 3.141592653589793238f;
  46.             double doublePI = 3.141592653589793238;
  47.             // Print the results on the console
  48.             Console.WriteLine("Float PI is: " + floatPI); // Float PI is: 3.141593 only 7 digits
  49.             Console.WriteLine("Double PI is: " + doublePI); // Double PI is: 3.14159265358979  16 digits
  50.             decimal decimalPI = 3.14159265358979323846m;
  51.             Console.WriteLine(decimalPI); // 3.14159265358979323846
  52.  
  53.             // 3. Char
  54.             char myFirstLetter = 'S';
  55.             Console.WriteLine((int)myFirstLetter);
  56.             char symbol = (char)5;
  57.             char myChar = '\u0065';
  58.             Console.WriteLine(myChar);
  59.             myChar = '\uffff';
  60.             Console.WriteLine(myChar);
  61.             // escaping
  62.             char myEscape = '\n'; // \n \t \r \' \\ \" \uXXXX
  63.  
  64.             // 4. String (default null) Reference, value in the heap
  65.             string myName = "Stoyan Cheresharov";
  66.             string path = @"D:\CamtasiaVideos"; // instead of D:\\CamtasiaVideos
  67.  
  68.             Console.WriteLine($"The Path is {path}");
  69.  
  70.             // 5. Bool (default false)
  71.             bool myBool = true; // false | true
  72.  
  73.             // 6. Object (default null) Reference, value in the heap
  74.             Object myObject = 3;
  75.  
  76.             Nullable<int> i1 = null;
  77.             int? i2 = i1;
  78.  
  79.             // typeof()
  80.             // Console.WriteLine(typeof(i1)); // error
  81.             // Used to obtain the System.Type object for a type. A typeof expression takes the following form:
  82.             System.Type type = typeof(int);
  83.             int i = 0;
  84.             type = i.GetType();
  85.             Console.WriteLine(type);
  86.  
  87.             // sizeof - Used to obtain the size in bytes for an unmanaged type.
  88.             Console.WriteLine(sizeof(sbyte)); // 1
  89.             // Unmanaged types include:
  90.             // The simple types that are listed in the following table:
  91.             // Expression Constant value
  92.             //sizeof(sbyte)   1
  93.             //sizeof(byte)    1
  94.             //sizeof(short)   2
  95.             //sizeof(ushort)  2
  96.             //sizeof(int) 4
  97.             //sizeof(uint)    4
  98.             //sizeof(long)    8
  99.             //sizeof(ulong)   8
  100.             //sizeof(char)    2(Unicode)
  101.             //sizeof(float)   4
  102.             //sizeof(double)  8
  103.             //sizeof(decimal) 16
  104.             //sizeof(bool)    1
  105.  
  106.             Console.WriteLine("Hello World! The sum is " + sum);
  107.             Console.WriteLine("-----------------------");
  108.             Console.WriteLine((char)65);
  109.             Console.WriteLine((int)'D');
  110.             Console.WriteLine('\u0065');
  111.             int? myVanya = null;
  112.             Console.WriteLine("Vanya is " + myVanya.ToString() + " years old!");
  113.             Console.WriteLine(sizeof(long));
  114.             int myDesiInt = 10;
  115.             // double myDesiDouble = 1.2;
  116.             int myDesiDouble = 3;
  117.             Console.WriteLine("Desi " + ((double)myDesiInt / myDesiDouble));
  118.             // Console.WriteLine("Desi " + ((myDesiInt / myDesiDouble));
  119.  
  120.             // Ctrl+r,r - refactoring/replace a name/string
  121.             // Not possible
  122.             //int? implicitConvertInt = 0;
  123.             //if (implicitConvertInt) { // Can not implicitly convert type int to bool
  124.             //}
  125.             //Object implicitConverToObj = null;
  126.             //if (implicitConverToObj) { // Can not implicitly convert type Obj to bool
  127.             //}
  128.  
  129.             myDesiInt++;
  130.             Console.WriteLine(myDesiInt);
  131.             Console.WriteLine((myDesiInt > 18) ? "You are an adult" : "You are young");
  132.             byte myTest = 1;
  133.             Console.WriteLine(myTest);
  134.             Console.WriteLine(myTest << 1);
  135.             Console.WriteLine(myTest << 2);
  136.             myTest <<= 2;
  137.             Console.WriteLine(myTest);
  138.             byte myGeorgi = 8;
  139.             Console.WriteLine(myTest | myGeorgi);
  140.  
  141.             int squarePerimeter = 17;
  142.             double squareSide = squarePerimeter / 4.0;
  143.             double squareArea = squareSide * squareSide;
  144.             Console.WriteLine(squareSide); // 4.25
  145.             Console.WriteLine(squareArea); // 18.0625
  146.             int a = 5;
  147.             int b = 4;
  148.             Console.WriteLine(a + b); // 9
  149.             Console.WriteLine(a + b++); // 9
  150.             Console.WriteLine(a + b); // 10
  151.             Console.WriteLine(a + (++b)); // 11
  152.             Console.WriteLine(a + b); // 11
  153.             Console.WriteLine(14 / a); // 2
  154.             Console.WriteLine(14 % a); // 4
  155.             int one = 1;
  156.             int zero = 0;
  157.             // Console.WriteLine(one / zero); // DivideByZeroException
  158.             double dMinusOne = -1.0;
  159.             double dZero = 0.0;
  160.             Console.WriteLine(dMinusOne / zero); // -Infinity
  161.             Console.WriteLine(one / dZero); // Infinity
  162.             Console.Clear();
  163.             Console.Write("Stoyan ");
  164.             Console.Write("Cheresharov \n\r");
  165.             Console.WriteLine("My name is Desi. I am {0} years old. my favorite number is {1}", myDesiInt, 3);
  166.             Console.WriteLine("| {0,10:######} |", 12);
  167.             Console.Clear();
  168.             Thread.CurrentThread.CurrentCulture =
  169.             CultureInfo.GetCultureInfo("bg-Bg");
  170.  
  171.  
  172.             Console.WriteLine("| {0,10:C} |", 120000.4532);
  173.             Console.Clear();
  174.             Console.Write("Please eneter your age: ");
  175.             string inputVariable = Console.ReadLine();
  176.             int age = int.Parse(inputVariable);
  177.             // double.TryParse(inputVariable,out );
  178.             // Convert.ToInt16();
  179.             Console.WriteLine(age + 10);
  180.  
  181.             Console.OutputEncoding = Encoding.UTF8;
  182.  
  183.             Console.ForegroundColor = ConsoleColor.Green;
  184.             // Console.BackgroundColor = ConsoleColor.Blue;
  185.             Console.SetCursorPosition(5, 10);
  186.             Console.WriteLine("Това е кирилица: ☺");
  187.  
  188.             Thread.CurrentThread.CurrentCulture =
  189.             CultureInfo.GetCultureInfo("en-GB");
  190.  
  191.             Console.WriteLine("Your balance is {0, 10:C2}", 1234567.8904534);
  192.  
  193.             int secondNumber = 3;
  194.             int firstNumber = 2;
  195.             if (secondNumber > firstNumber)
  196.             {
  197.                 // int biggerNumber = secondNumber;
  198.                 Console.WriteLine(secondNumber);
  199.             }
  200.  
  201.             char ch = 'X';
  202.             if (ch == 'A' || ch == 'a')
  203.             {
  204.                 Console.WriteLine("Vowel [ei]");
  205.             }
  206.             else if (ch == 'E' || ch == 'e')
  207.             {
  208.                 Console.WriteLine("Vowel [i:]");
  209.             }
  210.             else if (ch == 'I' || ch == 'i')
  211.             {
  212.                 Console.WriteLine("Vowel [ai]");
  213.             }
  214.             else if (ch == 'O' || ch == 'o')
  215.             {
  216.                 Console.WriteLine("Vowel [ou]");
  217.             }
  218.             else if (ch == 'U' || ch == 'u')
  219.             {
  220.                 Console.WriteLine("Vowel [ju:]");
  221.             }
  222.             else
  223.             {
  224.                 Console.WriteLine("Consonant");
  225.             }
  226.  
  227.  
  228.             //switch (селектор)
  229.             //{
  230.             //    case целочислена - стойност - 1: конструкция; break;
  231.             //    case целочислена - стойност - 2: конструкция; break;
  232.             //    case целочислена - стойност - 3: конструкция; break;
  233.             //    case целочислена - стойност - 4: конструкция; break;
  234.             //    // …
  235.             //    default: конструкция; break;
  236.             //}
  237.  
  238.             //while (условие)
  239.             //{
  240.             //    тяло на цикъла;
  241.             //}
  242.  
  243.             // Initialize the counter
  244.             int counter = 0;
  245.             // Execute the loop body while the loop condition holds
  246.             while (counter <= 9)
  247.             {
  248.                 // Print the counter value
  249.                 Console.WriteLine("Number : " + counter);
  250.                 // Increment the counter
  251.                 counter++;
  252.             }
  253.  
  254.  
  255.             //  n! = (n - 1)!*n
  256.  
  257.             int n = int.Parse(Console.ReadLine());
  258.             // "decimal" is the biggest type that can hold integer values
  259.             decimal factorial = 1;
  260.             // Perform an "infinite loop"
  261.             while (true)
  262.             {
  263.                 if (n <= 1)
  264.                 {
  265.                     break;
  266.                 }
  267.                 factorial *= n;
  268.                 n--;
  269.             }
  270.             Console.WriteLine("n! = " + factorial);
  271.  
  272.             int myDoTest = 0;
  273.             do
  274.             {
  275.                 Console.Write("Please enetr a number betwen 0 and 5: ");
  276.                 myDoTest = int.Parse(Console.ReadLine());
  277.             } while (myDoTest > 5 || myDoTest < 0);
  278.  
  279.             //for (инициализация; условие; обновяване)
  280.             //{
  281.             //    тяло на цикъла;
  282.             //}
  283.  
  284.             for (int j = 0; j <= 10; j++)
  285.             {
  286.                 Console.Write(j + " ");
  287.             }
  288.  
  289.             int t = 0;
  290.             while (t < 10)
  291.             {
  292.                 // i++;
  293.                 // break;
  294.                 if (t % 2 == 0)
  295.                 {
  296.                     t++;
  297.                     continue;
  298.                 }
  299.                 Console.WriteLine("t = " + t);
  300.                 t++;
  301.             }
  302.  
  303.             int[] numbers = { 2, 3, 5, 7, 11, 13, 17, 19 };
  304.             foreach (int k in numbers)
  305.             {
  306.                 Console.Write(" " + k);
  307.             }
  308.             Console.WriteLine();
  309.  
  310.             String[] towns = { "Sofia", "Plovdiv", "Varna", "Bourgas" };
  311.             foreach (String town in towns)
  312.             {
  313.                 Console.Write(" " + town);
  314.             }
  315.  
  316.             int special = 34;
  317.             Console.WriteLine($"This is my variable {special}");
  318.            
  319.             /*
  320.             // Convert to binary system
  321.             Console.Write("Please enter a number to convert: ");
  322.             // with 340282366920938000000000000000000000000
  323.             // System.OverflowException: Value was either too large or too small for an Int32.
  324.             int number2Convert = int.Parse(Console.ReadLine());
  325.             int[] binaryNumber = new int[128]; // the default value is 0
  326.             int digitCounter = 127;
  327.             while(number2Convert > 0 && digitCounter > 0)
  328.             {
  329.                 binaryNumber[digitCounter] = number2Convert % 2;
  330.                 digitCounter--;
  331.                 number2Convert /= 2;
  332.                 Console.WriteLine(number2Convert);
  333.             }
  334.             foreach(var digit in binaryNumber)
  335.             {
  336.                 Console.Write(digit);
  337.             }
  338.             Console.WriteLine();
  339.             Console.WriteLine(Math.Pow(2, 128)); // 3.40282366920938E+38
  340.             // Console.WriteLine("{0,10:N}", Math.Pow(2, 128)); // 340,282,366,920,938,000,000,000,000,000,000,000,000.00
  341.             // Console.WriteLine("{0,10:D}", Math.Pow(2, 128)); // Exception
  342.             Console.WriteLine("{0,10:F0}", Math.Pow(2, 128)); // 340282366920938000000000000000000000000
  343.             */
  344.         }
  345.     }
  346. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement