I want to be able to insert an array of integer as standard input which can has a length of 1000000. I am trying to do that using this code but the array will be only a size of 254, (I read from an article that Console.ReadLine take only 254 charecter).

Note: Every character of the array is between 1 to 6 and the first line of the code numThrows represents the length of the array.

 int numThrows = Convert.ToInt32(Console.ReadLine()); // length of array
 string str = Console.ReadLine();
 int[] arr = new int[numThrows];
 arr = str.Select(c => Convert.ToInt32(c.ToString())).ToArray();

1 Answers

Community On Best Solutions

You can increase the limit by writing your own ReadLine function.

        const int BufferLimit = 10000;
        public static string ReadLine()
            Stream s = Console.OpenStandardInput(BufferLimit);
            byte[] Buffer = new byte[BufferLimit];
            int Length = s.Read(Buffer, 0, BufferLimit);
            return new string(Encoding.UTF7.GetChars(Buffer, 0, Length));