Advertisement
sergezhu

Untitled

Apr 23rd, 2023
962
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.38 KB | None | 0 0
  1. namespace ConsoleApp1;
  2.  
  3. using System.Text;
  4.  
  5. public class Task14
  6. {
  7.     public void Run()
  8.     {
  9.         Console.InputEncoding = Encoding.Unicode;
  10.         Console.OutputEncoding = Encoding.Unicode;
  11.  
  12.         bool canExit = false;
  13.  
  14.         while ( canExit == false )
  15.         {
  16.             Console.Clear();
  17.             Console.WriteLine( $"Input name" );
  18.             string name = Console.ReadLine();
  19.             int nameWidth = name.Length;
  20.  
  21.             Console.Write( $"Input border char: " );
  22.             char borderChar = Console.ReadKey().KeyChar;
  23.  
  24.             int borderThickness = 1;
  25.             int borderLeftThickness = borderThickness;
  26.             int borderRightThickness = borderThickness;
  27.             int borderWidth = borderLeftThickness + nameWidth + borderRightThickness;
  28.             int borderHeight = 3;
  29.             int nameRowIndex = 1;
  30.  
  31.             Console.WriteLine();
  32.            
  33.             for ( int rowIndex = 0; rowIndex < borderHeight; rowIndex++ )
  34.             {
  35.                 string line;
  36.    
  37.                 if ( rowIndex == nameRowIndex )
  38.                 {
  39.                     string borderPart = new string( borderChar, borderThickness );
  40.                     line = $"{borderPart}{name}{borderPart}";
  41.                 }
  42.                 else
  43.                 {
  44.                     line = new string( borderChar, borderWidth );
  45.                 }
  46.  
  47.                 Console.WriteLine( line );
  48.             }
  49.  
  50.             Console.WriteLine();
  51.  
  52.             string properlyExitAnswer = "n";
  53.             Console.WriteLine( $"Continue? Enter \'{properlyExitAnswer}\' for exit" );
  54.             string continueAnswer = Console.ReadLine();
  55.  
  56.             canExit = string.Equals( continueAnswer, properlyExitAnswer );
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement