wingman007

ConsoleInputOutput

Nov 7th, 2015
423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.97 KB | None | 0 0
  1. using System;
  2. using System.Globalization;
  3. using System.Text;
  4. using System.Threading;
  5.  
  6. class Program
  7. {
  8.     enum Colors { Red = 1, Green, Blue }
  9.     static void Main()
  10.     {
  11.         //  Console.Write("Stoyan\r\n" );
  12.         //Console.Write("Stoyan" + Environment.NewLine);
  13.         //Console.Write("Ivan" + Environment.NewLine);
  14.         //Console.Write("Petko" + Environment.NewLine);
  15.         /*
  16.         int a = 5;
  17.         // string s = "The value of a is ";
  18.         Console.WriteLine(a);
  19.         Console.WriteLine("The value of a is " + (a + 6));
  20.  
  21.         int age = 52;
  22.         string name = "Stoyan";
  23.  
  24.         Console.WriteLine("My name is {0}. I am {1} years old!", name, age, "extra");
  25.         Console.WriteLine($"My name is {name}. I am {age} years old!");
  26.         */
  27.         // index[,aligment][:stringFormat]
  28.  
  29.         // Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-CA");
  30.         // Thread.CurrentThread.CurrentCulture = new CultureInfo("es-ES");
  31.         //Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
  32.  
  33.         // Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
  34.  
  35.         //// 1. Number standard
  36.         //Console.WriteLine("Your balance is {0,-20:C2}", 12333.3445); // + 34.45678
  37.         //for (int i = 0; i < 10; i++)
  38.         //{
  39.         //    Console.WriteLine("{0,20:C2}|{1,20:c4}", 12333.3445, 432432.4567);
  40.         //}
  41.         //Console.WriteLine("This number: {0:D6}", 23);
  42.         //Console.WriteLine("This number: {0:F3}", 24234343.43254);
  43.         //Console.WriteLine("This number: {0:N3}", 24234343.43254);
  44.         //Console.WriteLine("This number: {0:P4}", 0.43254);
  45.         //Console.WriteLine("This number: {0:X4}", 43254);
  46.  
  47.         // 1.2. NUmber Custom
  48.         // Console.WriteLine("This number: {0:000000.###########}", 43254.432);
  49.  
  50.         // 2. Date
  51.         // DateTime today = new DateTime(2015, 11, 7, 12, 14, 34);
  52.  
  53.         // Console.WriteLine(today);
  54.         // 2.1. standard
  55.         //Console.WriteLine("Today is: {0:D}", today);
  56.         //Console.WriteLine("Today is: {0:d}", today);
  57.         //Console.WriteLine("Today is: {0:T}", today);
  58.         //Console.WriteLine("Today is: {0:Y}", today);
  59.         //Console.WriteLine("Today is: {0:y}", today);
  60.  
  61.         //// 2.2. Custom
  62.         //Console.WriteLine("Today is: {0:yyyy+MM+dd}", today);
  63.  
  64.         // 3. Enum standard
  65.         // Console.WriteLine((int)Colors.Blue);
  66.  
  67.         //Console.WriteLine("{0:G}", Colors.Blue);
  68.         //Console.WriteLine("{0:D}", Colors.Blue);
  69.         //Console.WriteLine("{0:X}", Colors.Blue);
  70.  
  71.         // 2.Reading
  72.         // int c = Console.Read();
  73.         // Console.ReadLine();
  74.         // Console.ReadKey();
  75.  
  76.         // Console.WriteLine("Char {0} is {1}", (char)c, c);
  77.  
  78.         // Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
  79.  
  80.  
  81.         // 2.1. Parse
  82.         //Console.Write("How old are you?: ");
  83.         //string ageString = Console.ReadLine();
  84.         //int age = int.Parse(ageString);
  85.         //Console.WriteLine(age + 10);
  86.  
  87.         //Console.Write("What is your balance?: ");
  88.         //string balanceString = Console.ReadLine();
  89.         //float balance = 0.0f;
  90.         //try
  91.         //{
  92.         //    balance = float.Parse(balanceString);
  93.         //}
  94.         //catch (FormatException)
  95.         //{
  96.         //    Console.WriteLine("Please enter the correct data!");
  97.         //}
  98.  
  99.         //Console.WriteLine("My balance will be {0:N5}", balance);
  100.  
  101.  
  102.         // 2.1.TryParse
  103.         //Console.Write("What is your balance?: ");
  104.         //string balanceString = Console.ReadLine();
  105.         //float balance = 0.0f;
  106.         //bool isCorrect = float.TryParse(balanceString, out balance);
  107.         //if (isCorrect)
  108.         //{
  109.         //    Console.WriteLine("Thank you!");
  110.         //}
  111.         //else
  112.         //{
  113.         //    Console.WriteLine("Please enter the correct data!");
  114.         //}
  115.         //Console.WriteLine(balance);
  116.  
  117.         //Console.Write("What is your balance?: ");
  118.         //string balanceString = Console.ReadLine();
  119.         //try
  120.         //{
  121.         //    float balance = Convert.ToSingle(balanceString);
  122.         //}
  123.         //catch (FormatException)
  124.         //{
  125.         //    Console.WriteLine("Please enetr the correct data!");
  126.         //}
  127.  
  128.         ConsoleKeyInfo cki = Console.ReadKey();
  129.  
  130.         Console.WriteLine("Key: " + cki.Key);
  131.         Console.WriteLine("KeyChar: " + cki.KeyChar);
  132.         Console.WriteLine("Modifiers: " + cki.Modifiers);
  133.  
  134.         int x = 0, y = 10;
  135.  
  136.         Console.Clear();
  137.         do
  138.         {
  139.             while (!Console.KeyAvailable)
  140.             {
  141.                 Console.Clear();
  142.                 Console.SetCursorPosition(x, y);
  143.                 Console.WriteLine("*");
  144.                 if ( x < 79) x++;
  145.                 System.Threading.Thread.Sleep(100);
  146.             }
  147.             cki = Console.ReadKey();
  148.             Console.SetCursorPosition(10, 1);
  149.             Console.BackgroundColor = ConsoleColor.Blue;
  150.             Console.ForegroundColor = ConsoleColor.Gray;
  151.             Console.WriteLine("I am here and now!");
  152.         } while (cki.Key != ConsoleKey.RightArrow);
  153.  
  154.         // Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
  155.     // Console.InputEncoding = Encoding.UTF8;
  156.         // Console.OutputEncoding = Encoding.ASCII;
  157.         //Console.OutputEncoding = Encoding.UTF8;
  158.         //Console.WriteLine("Това е кирилица: ☺");
  159.  
  160.  
  161.         //Console.Write("Enter person name: ");
  162.         //string person = Console.ReadLine();
  163.  
  164.         //Console.Write("Enter company name: ");
  165.         //string company = Console.ReadLine();
  166.  
  167.         //Console.WriteLine("  Dear {0},", person);
  168.         //Console.WriteLine("We are pleased to tell you that " +
  169.         //  "{1} has accepted you to take part in the \"Programming Basics\"" +
  170.         //  " course. {1} wishes you a good luck!", person, company);
  171.  
  172.         //Console.WriteLine("  Yours,");
  173.         //Console.WriteLine("  {0}", company);
  174.  
  175.     }
  176. }
Advertisement
Add Comment
Please, Sign In to add comment