title: Populate 2D array from a particular coordinate
body: <p>I am trying to populate a 2D array vertically or horizontally from a given coordinate, if the indexes are in range. 
  Below is the program I can think about as of now. </p>
  
  <p>I just want to know if there is any other optimized way to perform this logical operation.</p>
  
  <pre><code>public static void Main()
  {
      var arr = new string[10,10];
      int x = 0;
      int y = 1;
      int len = 5;
      string somevalue = "x";
      string align = "vertical";
  
      int i = x;
      int j = y;
  
      try
      {
          while(len &gt; 0)
          {
              arr[i,j] = somevalue;
  
              if(align == "vertical") 
                  j++;
              else
                  i++;
  
              len--;
          }
      }
      catch(IndexOutOfRangeException ex)
      {
          Console.WriteLine(ex);
      }
  }
  </code></pre>