c# – Readline input is limited to 266 characters. How to fix


I am using the following code for the console (C #)

Console.Write("Код гугл ");
string google_map = Console.ReadLine();

You need to enter the Google map code, it is long enough and does not fit (((I was looking for an answer for a very long time. Please help


This turns out to be a limitation of the console .

Try this method:

var bufsize = 320;
Stream stream = Console.OpenStandardInput(bufsize);
TextReader inReader = (stream == Stream.Null) ?
            StreamReader.Null :
                new StreamReader(stream, Console.InputEncoding, false, bufsize, true));

Set the buffer size as needed.

The code was honestly spied on by ILSpy in the Console.In method.

The real limit is 254 characters: 256 bytes buffer size, plus two bytes reserved for CRLF. Likewise, if you manually set bufsize actual size will be two bytes less.

In reality, I failed to make the buffer smaller than 256.

If you want to correctly handle characters from other languages ​​and set Console.InputEncoding = Encoding.Unicode; , do not forget that your buffer will consume two bytes per character. If you, for example, set the buffer size to 320, then this will only give 160 unicode characters (and will be automatically raised to 256).

Scroll to Top