这个
docs
Console.ReadLine
说:
默认情况下,该方法从256个字符的输入缓冲区读取输入。因为这包括环境.NewLine字符,该方法可以读取最多包含254个字符的行。要读取较长的行,请调用OpenStandardInput(Int32)方法。
不过,我可以读更多的字符刚刚好。运行一个简单的程序,如:
string s = Console.ReadLine();
Console.WriteLine(s);
Console.WriteLine(s.Length);
Console.ReadKey();
输入如下:
aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeeffffffffffgggggggggghhhhhhhhhhiiiiiiiiiijjjjjjjjjjaaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeeffffffffffgggggggggghhhhhhhhhhiiiiiiiiiijjjjjjjjjjaaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeeffffffffffgggggggggghhhhhhhhhhiiiiiiiiiijjjjjjjjjjaaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeeffffffffffgggggggggghhhhhhhhhhiiiiiiiiiijjjjjjjjjjaaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeeffffffffffgggggggggghhhhhhhhhhiiiiiiiiiijjjjjjjjjj
here
那么这些文档是过时的,还是这里的“默认”键?
杰里米发现了4096的极限
source code
.
Console.ReadLine()
其中.NETCore3.1进程通过
fwProcess.StandardInput.WriteLine(Serialize(<some stuff>));
当.NET框架进程被.NET核心进程替换时,这种方法也能起作用。
如果有用的话,这就是我正在运行的代码。
ProcessStartInfo processInfo = new ProcessStartInfo {
CreateNoWindow = true,
FileName = "ConsoleApp2.exe",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardInput = true
};
StringBuilder s = new StringBuilder();
var proc = Process.Start(processInfo);
int n = 1_000_000_000;
for (int i = 0; i < n; i++)
s.Append("a");
proc.StandardInput.WriteLine(s.ToString());
string s = proc.StandardOutput.ReadLine();
Console.WriteLine(s.Length == n); // logs True
Console.ReadKey();
控制台AP2:
string s = Console.ReadLine();
Console.WriteLine(s);