Venciity

[Jumpstart C#] Console Demos - Priting to console

Jan 22nd, 2014
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.30 KB | None | 0 0
  1. using System;
  2.  
  3. class PrintingToConsole
  4. {
  5.     static void Main()
  6.     {
  7.         string greeting = "Hi!";
  8.         string name = "Marry";
  9.         int age = 18;
  10.         Console.Write("{0} My Name is {1}.", greeting, name);
  11.         Console.WriteLine("<-- Introduction");
  12.         Console.Write("I am {0} years old.", age);
  13.         Console.Write("<-- age{0}", Environment.NewLine);
  14.         Console.Write("How old are you?");
  15.         Console.Write("<-- Question");
  16.         Console.WriteLine();
  17.         Console.Write("What's your name?");
  18.         Console.Write("<-- Another Question\r\n");//not recommended use
  19.         Console.Write("This sentence is on a new line");
  20.  
  21.         Console.WriteLine();
  22.         Console.WriteLine();
  23.  
  24.         double realNumber = 1.2345;
  25.         Console.WriteLine("{0:0.000000}", realNumber);
  26.         //1.234500
  27.         Console.WriteLine("{0:0.000}", realNumber);
  28.         //1.235  
  29.  
  30.         int a = 2, b = 3;
  31.         Console.Write("{0} + {1} =", a, b);
  32.         Console.WriteLine(" {0}", a + b);
  33.         // 2 + 3 = 5
  34.  
  35.         Console.WriteLine("{0} * {1} = {2}",
  36.                           a, b, a * b);
  37.         // 2 * 3 = 6
  38.  
  39.         float pi = 3.14159206f;
  40.         Console.WriteLine("{0:F2}", pi); // 3,14
  41.         Console.WriteLine();
  42.  
  43.         decimal colaPrice = 1.20M;
  44.         string cola = "Coca Cola";
  45.  
  46.         decimal fantaPrice = 1.10M;
  47.         string fanta = "Fanta Madness";
  48.  
  49.         decimal shumenskoPrice = 2.20M;
  50.         string shumensko = "Shhhumensko Premium";
  51.  
  52.  
  53.         Console.WriteLine("Menu");
  54.         Console.WriteLine("1. {0} - {1:C}", cola, colaPrice);
  55.         Console.WriteLine("2. {0} - {1:C}", fanta, fantaPrice);
  56.         Console.WriteLine("3. {0} - {1:C}", shumensko, shumenskoPrice);
  57.  
  58.         Console.WriteLine("   Refresh your day!");
  59.  
  60.         Console.WriteLine();
  61.         Console.WriteLine("----------------------------------");
  62.         Console.WriteLine("{0,-19} | {1,10:C} |", cola, colaPrice);
  63.         Console.WriteLine("{0,-19} | {1,10:C} |", fanta, fantaPrice);
  64.         Console.WriteLine("{0,-19} | {1,10:C} |", shumensko, shumenskoPrice);
  65.         Console.WriteLine("{0,-19} | {1,10:C} |", "Cheese", 9.786);
  66.         Console.WriteLine("----------------------------------");
  67.  
  68.         Console.WriteLine();
  69.         Console.WriteLine("The hex value of {0} is {0:X}.", 32378);
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment