title: Returning 2 Dimensional array in asp.net c#
body: <p>I'm using .asmx web service that will return 2 dimensional array where I want to return like <code>row1={'id1','name1'}, row2={'id2','name2'}</code> but I'm not being able to do so. </p>
  
  <p><strong>Code Section</strong></p>
  
  <pre><code>[WebMethod]
  [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
  public Array getAlbumsAndPhotos()
  {
      DataTable resultText = new DataTable();
      resultText = AdminUserDataAccess.getAlbumsAndPhotosforAsmx();
      string[,] ResultResponse = new string[resultText.Rows.Count , resultText.Columns.Count];
      for (int i = 0; i &lt; resultText.Rows.Count; i++)
      {
  
          for (int j = 0; j &lt; resultText.Columns.Count; j++)
          {
              ResultResponse[i, j] = resultText.Rows[i][j].ToString();
  
          }
      }
      return ResultResponse;
  }
  </code></pre>
  
  <p>This gives me output as:</p>
  
  <pre><code>    [0,0]:"id1"
      [0,1]:"name1"
      [1,0]:"id2"
      [1,1]:"name2"
  </code></pre>
  
  <p>I want two rows to be returned not four with single 0th index(with id1 and name1) and 1st index(with id2 and name2). Some type of nested array output is expected. But I'm not being able to do so. Any help is appreciated. :)</p>
  
  <p><strong>Edit: Solution</strong></p>
  
  <pre><code>    [WebMethod]
  [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
  public List&lt;string[]&gt; getAlbumsAndPhotos()
  {
      DataTable resultText = new DataTable();
      resultText = AdminUserDataAccess.getAlbumsAndPhotosforAsmx();
      string[] rowsValues = new string[resultText.Rows.Count];
      var list = new List&lt;string[]&gt;();
      for (int i = 0; i &lt; resultText.Rows.Count; i++)
      {
          string col1 = resultText.Rows[i][0].ToString();
          string col2 = resultText.Rows[i][1].ToString();
          list.Add(new[] { col1, col2});
      }
      return list;
  </code></pre>
  
  <p>I can use List or Array list to implement this. Thanks. :)</p>