Problem: You need to input multiple rows in the console, but want to accept them, rather than a limited row.
Solution:
Static String Acceptmultiline ()
{
Consolekeyinfo cki;
Console. treatcontrolcasinput = True ; // Prevents Ctrl + C Replication
Console. writeline ( " Press the F10 key to quit: \ n " );
String Result = String . Empty;
Do
{
Cki = Console. readkey ();
Result + = Cki. keychar;
If (Cki. Key = Consolekey. Enter)
{
Result + = System. environment. newline; // If you press enter, a line feed sign is added.
}
} While (Cki. Key ! = Consolekey. F10 ); // Press F10 to exit
Return Result;
}
Public Static Void Main ( String [] ARGs)
{
String S = Acceptmultiline ();
Console. writeline (s );
Console. Readline ();
}
Thanks to Jeffery for reminding you:
ModifiedCode:
Static String Acceptmultilinechars2 ()
{
Consolekeyinfo cki;
Console. treatcontrolcasinput = True ; // Prevents Ctrl + C Replication
Console. writeline ( " Press the CTRL + enter key to quit: \ n " );
String Result = String . Empty;
Do
{
Cki = Console. readkey ();
If (Cki. Key = Consolekey. Enter)
{
Result + = System. environment. newline; // If you press enter, a line feed sign is added.
Console. setcursorposition ( 0 , Console. cursortop + 1 ); // Move the cursor down a row
}
Result + = Cki. keychar;
} While (Cki. Key ! = Consolekey. Enter | (Cki. Modifiers & Lelemodifiers. Control) = 0 ); // Press Ctrl + enter to exit
Return Result;
}