2019. december 20., péntek

2019.12.20. Output formázások


namespace adatlopo
{
    class Program
    {
        static void Main(string[] args)
        {
            //Adatlopó
            //Írjunk programot, mely adatokat kér be a
            //felhasználótól, majd különböző formában
            //kiírja azokat.
            //Szorgalmi: oldd meg a soronkénti
            //kiírásokat két oszloposan.

            Console.Title = "Ez nem adatlopó program :)";

            const string hackerCode = "DEVIL"; //ez nem változik a program során: konstans érték
            Console.Write("Felhasználónév: ");           
            string userName = Console.ReadLine();
            Console.Write("Jelszó: ");           
            string password = Console.ReadLine();
            Console.Write("IP cím: ");           
            string ip = Console.ReadLine();
            Console.Write("Kedvenc torrent server: ");           
            string torrent = Console.ReadLine();
            Console.Write("Letöltések száma havonta: ");
            string downloads = Console.ReadLine();
           
            Console.WriteLine();
            Console.WriteLine();
           
            //Kiírjuk a hacker képernyőjére a megszerzett adatokat:
            Console.WriteLine("To: {0} ",hackerCode );
            Console.WriteLine("Username: {0} ",userName );
            Console.WriteLine("Password: {0} ",password );
            Console.WriteLine("IP: {0} ",ip );
            Console.WriteLine("Torrent: {0} ",torrent );
            Console.WriteLine("Downloads: {0} ",downloads );

            Console.WriteLine();
            Console.WriteLine();

            //Egy kicsit szebben így néz ki (balra rendezett):
            Console.WriteLine("To:          {0}",hackerCode );
            Console.WriteLine("Username:    {0}",userName );
            Console.WriteLine("Password:    {0}",password );
            Console.WriteLine("IP:          {0}",ip );
            Console.WriteLine("Torrent:     {0}",torrent );
            Console.WriteLine("Downloads:   {0}",downloads );

            Console.WriteLine();
            Console.WriteLine();

            //Ugyanez elegánsan megoldva (jobbra rendezett):
            Console.WriteLine("To:          {0,19}",hackerCode );
            Console.WriteLine("Username:    {0,19}",userName );
            Console.WriteLine("Password:    {0,19}",password );
            Console.WriteLine("IP:          {0,19}",ip );
            Console.WriteLine("Torrent:     {0,19}",torrent );
            Console.WriteLine("Downloads:   {0,19}",downloads );
     
            Console.WriteLine();
            Console.WriteLine();  
             
            //ugyanezeket így is kiírhatnánk (balra rendezett):
            Console.WriteLine("To: {0}, Username: {1}, Password: {2}, IP: {3}, Torrent: {4}, Downloads: {5}", hackerCode, userName, password, ip, torrent, downloads);
           
            Console.WriteLine();
            Console.WriteLine();    
   
            //vagy így (jobbra rendezett):
            Console.WriteLine("To: {0,8}, Username: {1,8}, Password: {2,8}, IP: {3,19}, Torrent: {4,8}, Downloads: {5,4}", hackerCode, userName, password, ip, torrent, downloads);

            //Ugyanez két oszloposan megoldva (jobbra rendezett):
            Console.WriteLine();
            Console.WriteLine();
           
            Console.WriteLine("To:          {0,19} IP:          {1,19}", hackerCode,ip);
            Console.WriteLine("Username:    {0,19} Torrent:     {1,19}", userName,torrent);
            Console.WriteLine("Password:    {0,19} Downloads:   {1,19}", password,downloads);

            Console.ReadLine();
        }
    }
}

7 megjegyzés: