Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Globalization;
- using System.Text;
- using System.Threading;
- class PrintNewLine
- {
- enum Color { Yellow = 1, Blue, Green };
- static DateTime thisDate = DateTime.Now;
- static void Main()
- {
- /*
- string name = "Marry";
- int year = 1987;
- Console.WriteLine("{0} was born in {1}.", name, year);
- // Marry was born in 1987.
- // Interpolated Strings – from C#6 (VS 2015)
- Console.WriteLine($"{name} was born in {year}.");
- Console.WriteLine("I am writing now: {0, 10:F2}|{1, 10}",
- 2.34567, 3.145676);
- int a = Console.Read();
- Console.WriteLine(a);
- Console.WriteLine((char)a);
- Console.WriteLine("{0} + {1} = {2}", 1, 2, 1 + 2);
- while (true)
- {
- Console.WriteLine(Console.KeyAvailable);
- if (Console.KeyAvailable) {
- ConsoleKeyInfo cki = Console.ReadKey();
- Console.WriteLine(cki);
- }
- }
- */
- /*
- ConsoleKeyInfo cki;
- // Prevent example from ending if CTL+C is pressed.
- Console.TreatControlCAsInput = true;
- Console.WriteLine("Press any combination of CTL, ALT, and SHIFT, and a console key.");
- Console.WriteLine("Press the Escape (Esc) key to quit: \n");
- do
- {
- cki = Console.ReadKey();
- Console.Write(" --- You pressed ");
- if ((cki.Modifiers & ConsoleModifiers.Alt) != 0) Console.Write("ALT+");
- if ((cki.Modifiers & ConsoleModifiers.Shift) != 0) Console.Write("SHIFT+");
- if ((cki.Modifiers & ConsoleModifiers.Control) != 0) Console.Write("CTL+");
- Console.WriteLine(cki.Key.ToString());
- } while (cki.Key != ConsoleKey.Escape);
- */
- // int symbol = Console.Read();
- // Console.WriteLine("{0} = {1}", (char)symbol, symbol);
- /*
- if (!Console.IsInputRedirected)
- {
- Console.WriteLine("This example requires that input be redirected from a file.");
- return;
- }
- Console.WriteLine("About to call Console.ReadLine in a loop.");
- Console.WriteLine("----");
- String s;
- int ctr = 0;
- do
- {
- ctr++;
- s = Console.ReadLine();
- Console.WriteLine("Line {0}: {1}", ctr, s);
- } while (s != null);
- Console.WriteLine("---");
- */
- /*
- int a = int.Parse(Console.ReadLine());
- int b = int.Parse(Console.ReadLine());
- Console.WriteLine("{0} + {1} = {2}", a, b, a + b);
- Console.WriteLine("{0} * {1} = {2}", a, b, a * b);
- float f = float.Parse(Console.ReadLine());
- Console.WriteLine("{0} * {1} / {2} = {3}", a, b, f, a * b / f);
- */
- /*
- Console.WriteLine("{0,10:C3}", 1023.4567);
- Console.WriteLine("{0,10:D8}", -12345);
- Console.WriteLine("{0,10:E8}", -1234.5);
- Console.WriteLine("{0,10:F2}", -123.456);
- Console.WriteLine("{0,10:N2}", -1234.56);
- Console.WriteLine("{0,10:P2}", 0.45656);
- Console.WriteLine("{0,10:X5}", 254);
- Console.Clear();
- // Format a negative integer or floating-point number in various ways.
- Console.WriteLine("Standard Numeric Format Specifiers");
- Console.WriteLine(
- "(C) Currency: . . . . . . . . {0:C}\n" +
- "(D) Decimal:. . . . . . . . . {0:D}\n" +
- "(E) Scientific: . . . . . . . {1:E}\n" +
- "(F) Fixed point:. . . . . . . {1:F}\n" +
- "(G) General:. . . . . . . . . {0:G}\n" +
- " (default):. . . . . . . . {0} (default = 'G')\n" +
- "(N) Number: . . . . . . . . . {0:N}\n" +
- "(P) Percent:. . . . . . . . . {1:P}\n" +
- "(R) Round-trip: . . . . . . . {1:R}\n" +
- "(X) Hexadecimal:. . . . . . . {0:X}\n",
- -123, -123.45f);
- // Format the current date in various ways.
- Console.WriteLine("Standard DateTime Format Specifiers");
- Console.WriteLine(
- "(d) Short date: . . . . . . . {0:d}\n" +
- "(D) Long date:. . . . . . . . {0:D}\n" +
- "(t) Short time: . . . . . . . {0:t}\n" +
- "(T) Long time:. . . . . . . . {0:T}\n" +
- "(f) Full date/short time: . . {0:f}\n" +
- "(F) Full date/long time:. . . {0:F}\n" +
- "(g) General date/short time:. {0:g}\n" +
- "(G) General date/long time: . {0:G}\n" +
- " (default):. . . . . . . . {0} (default = 'G')\n" +
- "(M) Month:. . . . . . . . . . {0:M}\n" +
- "(R) RFC1123:. . . . . . . . . {0:R}\n" +
- "(s) Sortable: . . . . . . . . {0:s}\n" +
- "(u) Universal sortable: . . . {0:u} (invariant)\n" +
- "(U) Universal full date/time: {0:U}\n" +
- "(Y) Year: . . . . . . . . . . {0:Y}\n",
- thisDate);
- // Format a Color enumeration value in various ways.
- Console.WriteLine("Standard Enumeration Format Specifiers");
- Console.WriteLine(
- "(G) General:. . . . . . . . . {0:G}\n" +
- " (default):. . . . . . . . {0} (default = 'G')\n" +
- "(F) Flags:. . . . . . . . . . {0:F} (flags or integer)\n" +
- "(D) Decimal number: . . . . . {0:D}\n" +
- "(X) Hexadecimal:. . . . . . . {0:X}\n",
- Color.Green);
- */
- /*
- // Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-CA"); // en-US
- // Thread.CurrentThread.CurrentCulture = new CultureInfo("en-CA"); //
- Thread.CurrentThread.CurrentCulture = new CultureInfo("ro-RO");
- // CultureInfo.InvariantCulture;
- // Console.OutputEncoding = Encoding.ASCII;
- Console.OutputEncoding = Encoding.UTF8;
- Console.WriteLine("Това е кирилица: ☺");
- ConsoleKeyInfo cki = Console.ReadKey();
- Console.WriteLine("Key: {0}", cki.KeyChar);
- Console.WriteLine("Modifiers: {0}", cki.Modifiers);
- Console.WriteLine("Key: {0}", cki.Key);
- // date
- DateTime today = new DateTime(2015, 11, 7, 11, 23, 34);
- Console.WriteLine("Today is {0:d}", today);
- Console.WriteLine("Today is {0:D}", today);
- Console.WriteLine("Today is {0:t}", today);
- Console.WriteLine("Today is {0:T}", today);
- Console.WriteLine("Today is {0:Y}", today);
- Console.WriteLine("Today is {0:yyyy-MM-dd hh:mm:ss}", today);
- // currency
- Console.WriteLine("{0:C2}", 234.4567);
- Console.WriteLine("{0:D8}", 2344567);
- Console.WriteLine("{0:F8}", 23.44567);
- Console.WriteLine("{0:N8}", 3243423.44567);
- Console.WriteLine("{0:X8}", 3243423);
- Console.WriteLine("{0:00.0000000}", 3243423.434);
- Console.WriteLine("{0:00.000#####}", 3243423.434);
- // enum
- Console.WriteLine("The color is {0:G}", Color.Blue);
- Console.WriteLine("The color is {0:D}", Color.Blue);
- Console.WriteLine("The color is {0:X}", Color.Blue);
- Console.SetCursorPosition(40, 20);
- Console.ForegroundColor = ConsoleColor.Red;
- Console.BackgroundColor = ConsoleColor.Blue;
- Console.WriteLine("Here we go");
- */
- // Console.WriteLine(Console.Read());
- Console.WriteLine(Convert.ToInt32("1234"));
- Console.WriteLine(Convert.ToSingle("1234,44324"));
- Console.WriteLine(Convert.ToDouble("1234,44324")); // Notice ,
- int result;
- bool isOk = int.TryParse("32423", out result);
- // Console.WriteLine("First" + Environment.NewLine + "Second" + "First" + Environment.NewLine + "First" + Environment.NewLine + "First" + Environment.NewLine);
- // Environment.NewLine;
- int a = 0;
- string stringA = null;
- do
- {
- Console.Write("Please enter a number between 0 and 500: ");
- stringA = Console.ReadLine();
- // 1. int.Parse(); try catch
- try
- {
- a = int.Parse(stringA);
- }
- catch (FormatException)
- {
- Console.WriteLine("Please enter a proper number between 0 and 500!");
- }
- } while (!(0 <= a && a <= 500));
- Console.WriteLine("The number was: " + a);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment