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

9
  • 3
    I think this might be useful for you : stackoverflow.com/questions/890098/… Commented Mar 12, 2012 at 9:14
  • 3
    This code needs an unsafe keyword Commented Mar 12, 2012 at 9:14
  • @juergen d, why can't be this C#? Yeah, it is unsafe code, but possible. Commented Mar 12, 2012 at 9: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. Commented Mar 12, 2012 at 9:16
  • Is this to simply iterate over the contents of the array? Commented Mar 12, 2012 at 9:16

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.