1

Possible Duplicate:
Converting from a jagged array to double pointer in C#

I wanna convert array to pointer in c#.

double[] array;
//input something
fixed (double* pt = array) {
//.....

It successed. But I want to use it like this

How can I use double pointer?

double[][] array;
//...
fixed (double** pt = array) {
//...

when I convert it to double pointer, it doesn`t worked. How can I use double pointer?

(added) I already used "unsafe" at class like this

unsafe class Class1 {

and first example (using single pointer) was done well. I wanna use double pointer

Community
  • 1
  • 1
Temp
  • 109
  • 1
  • 11
  • 3
    I think this might be useful for you : http://stackoverflow.com/questions/890098/converting-from-a-jagged-array-to-double-pointer-in-c-sharp – orel Mar 12 '12 at 09:14
  • 3
    This code needs an `unsafe` keyword – Jodrell Mar 12 '12 at 09:14
  • @juergen d, why can't be this C#? Yeah, it is unsafe code, but possible. – Chuck Norris Mar 12 '12 at 09:14
  • 2
    `double[][]` is a jagged array (as opposed to a multi-dim array `double[,]`) and hence, is not a contiguous memory location. So it does not make sense to create pointer out of it. You perhaps need to fix out each individual array within. – VinayC Mar 12 '12 at 09:16
  • Is this to simply iterate over the contents of the array? – Jodrell Mar 12 '12 at 09:16
  • possibly similar to: http://stackoverflow.com/questions/890098/converting-from-a-jagged-array-to-double-pointer-in-c-sharp – ET13 Mar 12 '12 at 09:16
  • @VinayC : Jagged arrays are the only type this is possible with. – H H Mar 12 '12 at 09:19
  • @HenkHolterman, yes - I actually want to emphasis that jagged array is not a continuous block... so taking that address into a double** ptr does not make sense – VinayC Mar 12 '12 at 09:22
  • http://stackoverflow.com/questions/4033054/fixed-statement-with-jagged-array – Felix K. Mar 12 '12 at 09:33

1 Answers1

0

Why not do?

foreach(var doubleValue in array) {...}

Its safe and simple. Idea lifted from here.

If the array is jagged then perhaps a SelectMany would provide simple iteration.

Community
  • 1
  • 1
Jodrell
  • 34,946
  • 5
  • 87
  • 124