Best way to convert int[][] to int**?
<p>This is kind of a curiosity question.  I do have an existing solution, but I wonder if people know of a better approach.</p>

<p>My callers want to call me with int[][].  I have a routine that needs to process an int**.  What's the best way to do this conversion?  In other words:</p>

<pre><code>public static void Func1(int[][] data) {
  Func2(data); //how to do this?
}

private unsafe static void Func2(int** data) {
  //process data
}
</code></pre>

<p>Following is the best approach I could come up with.  It works fine, but I can't say I'm 100% happy with the recursive approach (and the O(data.Length) stack space it requires)</p>

<pre><code>public static void Main() {
  var test=new[] {
    new [] {10},
    new [] {20,30},
    new [] {40,50,60},
    new [] {70,80,90,100},
  };
  MySolution_Func1(test);
}

public unsafe static void MySolution_Func1(int[][] data) {
  var items=new int*[data.Length];
  Recurse(0, data, items);
}

public unsafe static void Recurse(int index, int[][] data, int*[] build) {
  if(index==data.Length) {
    fixed(int** finalp=build) {
      Func2(finalp);
    }
  } else {
    fixed(int* nextp=data[index]) {
      build[index]=nextp;
      Recurse(index+1, data, build);
    }
  }
}

private unsafe static void Func2(int** data) {
  for(var j=0; j&lt;4; ++j) {
    for(var i=0; i&lt;j+1; ++i) {
      Debug.WriteLine("{0},{1}: {2}", j, i, data[j][i]);
    }
  }
}
</code></pre>
