title: Length cannot be negative (Exception)
body: <p>i have been doing an exercise on codeeval:
  <a href="https://www.codeeval.com/open_challenges/30/submit/?lid=1335504" rel="nofollow">https://www.codeeval.com/open_challenges/30/submit/?lid=1335504</a></p>
  
  <p>here is my code</p>
  
  <pre><code>using System;
  using System.Text;
  using System.IO;
  using System.Collections.Generic;
  
  class Program
  {
      static void Main(string[] args)
      {
          using (StreamReader reader = File.OpenText(args[0]))
          while (!reader.EndOfStream)
          {
              StringBuilder result = new StringBuilder();
              string b = "";
              string c = "";
              string[] b2;
              string[] c2;
              int x = 0;
              string line = reader.ReadLine();
              if (null == line)
                  continue;
              // do something with line
              else{
              x = line.IndexOf(";");
              b = line.Substring(x +1);
              b2 = b.Split(',');
              c = line.Substring(0, (line.Length - ((b.Length) + 1)));
              c2 = c.Split(',');
              foreach (string u in b2) {
                      foreach (string i in c2)
                      {
                          if (int.Parse(u) == int.Parse(i))
                          {
                              result.Append(u + ",");
                          }
                      }
                  }
              Console.WriteLine(result.ToString().Substring(0, result.Length - 1));
              result.Clear();
              Array.Clear(b2, 0 , b2.Length);
              Array.Clear(c2, 0 , c2.Length);
              }
          }
      }
  }
  </code></pre>
  
  <p>When i run on my VS, it works on 1 string. However, it run one or two lines then gives me an exeception when i run it on codeeval. I don't know why the length can be negative...???</p>
  
  <blockquote>
    <p>Unhandled Exception: System.ArgumentOutOfRangeException: Cannot be
    negative. Parameter name: length   at System.String.Substring (Int32
    startIndex, Int32 length) [0x00000] in :0    at
    Program.Main (System.String[] args) [0x00000] in :0 
    [ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentOutOfRangeException:
    Cannot be negative. Parameter name: length   at
    System.String.Substring (Int32 startIndex, Int32 length) [0x00000] in
    :0    at Program.Main (System.String[] args)
    [0x00000] in :0</p>
  </blockquote>
  
  <p>the input are</p>
  
  <pre><code>68,69,70,71,72,73,74,75,76,77,78,79,80,81,82;78,79,80,81,82,83,84
  87,88,89,90,91,92,93;64,65,66,67,68
  87,88,89,90,91,92;81,82,83,84,85,86,87
  82,83,84,85,86;68,69,70,71,72,73,74,75,76,77,78,79,80
  78,79,80,81,82,83,84,85,86,87,88,89,90,91;67,68,69,70,71,72
  </code></pre>