Advertisement
sergezhu

Untitled

Apr 23rd, 2023
1,015
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.33 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.             int nameHeight = 1;
  21.  
  22.             Console.Write( $"Input border char: " );
  23.             char borderChar = Console.ReadKey().KeyChar;
  24.  
  25.             int borderThickness = 1;
  26.             int borderWidth = borderThickness * 2 + nameWidth;
  27.             int borderHeight = borderThickness * 2 + nameHeight;
  28.             int nameRowIndex = borderThickness;
  29.  
  30.             Console.WriteLine();
  31.            
  32.             for ( int rowIndex = 0; rowIndex < borderHeight; rowIndex++ )
  33.             {
  34.                 string line;
  35.    
  36.                 if ( rowIndex == nameRowIndex )
  37.                 {
  38.                     string borderPart = new string( borderChar, borderThickness );
  39.                     line = $"{borderPart}{name}{borderPart}";
  40.                 }
  41.                 else
  42.                 {
  43.                     line = new string( borderChar, borderWidth );
  44.                 }
  45.  
  46.                 Console.WriteLine( line );
  47.             }
  48.  
  49.             Console.WriteLine();
  50.  
  51.             string properlyExitAnswer = "n";
  52.             Console.WriteLine( $"Continue? Enter \'{properlyExitAnswer}\' for exit" );
  53.             string continueAnswer = Console.ReadLine();
  54.  
  55.             canExit = string.Equals( continueAnswer, properlyExitAnswer );
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement