0

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();
Zain Arshad
  • 1,885
  • 1
  • 11
  • 26
L. Dabbeet
  • 290
  • 1
  • 3
  • 14
  • [Console.SetIn()](https://learn.microsoft.com/en-us/dotnet/api/system.console.setin). What would the content of this array represent? How are you planning to input it? Pasting *something*? – Jimi Apr 13 '19 at 18:10
  • this array represents the throws of a dice, as every digit will be between 1 and 6, I am planning to create an array of million digits to try it. – L. Dabbeet Apr 13 '19 at 18:20
  • you can read it from file generate them randomly in your code... how you are supposed to write all the `10000` integers on CMD ... :/ – Zain Arshad Apr 13 '19 at 18:29
  • I know it seems strange, but it is homework for college, and they say it will be tested with an array that contains a million digits, and this was asked to be solved using standard input and output – L. Dabbeet Apr 13 '19 at 18:32
  • "I read from an article that Console.ReadLine take only 254 charecter" -- Hmm, I just tested this. It seams I can read more than 1000000 characters with a single `ReadLine()`. Where did you read this? – sticky bit Apr 13 '19 at 18:57
  • https://stackoverflow.com/questions/5557889/console-readline-max-length – L. Dabbeet Apr 14 '19 at 19:41

1 Answers1

2

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));
        }
Raphtaliyah
  • 207
  • 1
  • 6