C#:程序读取时大量文本被截断

C#: Large amounts of text cut off when read by program

嗨,我似乎找不到任何关于如何将信息从 console.writeline 存储到数组中的有用信息。

 Console.WriteLine("Please enter one or more sentences.");
 string text = Console.ReadLine();

如何将用户的句子存储到数组中?目前,如果我输入大量文本,它就会被剪切,希望一个数组将允许读取和排序所有文本。 谢谢!!

你可以与用户建立一种沟通方式,比如当他发送一个空行时它就结束了。然后执行以下操作:

Console.WriteLine("Please enter one or more sentences.");
string text;    
List<string> list = new List();

while (true) 
{
       text = Console.ReadLine();

      if (text.Length == 0)
          break;
      else
          list.Add(text);             
}

这是控制台的限制API,它是 256 个字符 (254 + CR LF)。 您可以使用

更改此限制
Console.SetIn(new StreamReader(Console.OpenStandardInput(8192)));

在 MSDN 论坛上找到:http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/51ad87c5-92a3-4bb3-8385-bf66a48d6953

您可以创建一个新的 ReadLine 方法,检查这个 post: Console.ReadLine() max length?