title: Stack overflow exception error in a recursive function
body: <p>I just started learning c# however I have some experience with java, so one of the things I wanted to do is to generate a 2d array map filled with 1's and 0's and recursively check if there is a path without stepping on 1's. </p>
  
  <p>However after writing the code and running it it shows me the stack overflow exception error. </p>
  
  <p>Where did I do something wrong?</p>
  
  <p>Edit: the end of the array(the cell with the largest value 9,9(it's a 10x10 array) in this case is set to 6 as the end point)</p>
  
  <p>Code for the recursive method:</p>
  
  <pre><code>public static int recursiveCheck(int[,] grid,int x, int y, int finalX, int finalY, int paths)
          {
              if (grid[x, y] == 6)
              {
                  paths++;
                  return paths;
              }
              if ((grid[x + 1, y] != 1) &amp;&amp; (x+1 &lt; finalX))
                  return recursiveCheck(grid, x + 1, y, finalX, finalY, paths);
              if ((grid[x, y+1] != 1) &amp;&amp; (y+1 &lt; finalY))
                  return recursiveCheck(grid, x, y+1, finalX, finalY, paths);
              if ((grid[x - 1, y] != 1) &amp;&amp; (x &gt; 0))
                      return recursiveCheck(grid, x - 1, y, finalX, finalY, paths);
              if (grid[x, y - 1] != 1 &amp;&amp; y &gt;0)
                      return recursiveCheck(grid, x, y - 1, finalX, finalY, paths);
              return 0;
          }
  </code></pre>
  
  <p>Array Initialization code:</p>
  
  <pre><code>public static int[,] gridGen()
          {
              int[,] grid = new int[10, 10];
              Random rnd = new Random();
              int lim;
              for (int i = 0; i &lt; 10; i++)
              {
                  for (int c = 0; c &lt; 10; c++)
                  {
                      lim = rnd.Next(0, 2);
                      //Console.WriteLine($"lim: {lim} ");
                      grid[i, c] = lim;
                  }
              }
              grid[0, 0] = 2;
              grid[grid.GetLength(0) - 1, grid.GetLength(1) - 1] = 6;
              for (int i = 0; i &lt; 10; i++)
              {
                  for (int c = 0; c &lt; 10; c++)
                  {
                      Console.Write(grid[i, c] + " ");
                  }
                  Console.WriteLine();
              }
              return grid;
          }
  </code></pre>