Create a subarray reference in C# (using unsafe ?)

Posted by Wam on Stack Overflow See other posts from Stack Overflow or by Wam
Published on 2010-04-08T08:59:41Z Indexed on 2010/04/08 9:03 UTC
Read the original article Hit count: 990

Hello there,

I'm refactoring a library we currently use, and I'm faced with the following problem.

We used to have the following stuff :

class Blah
{
    float[][] data;
    public float[] GetDataReference(int index)
    {
        return data[index];
    }
}

For various reasons, I have replaced this jagged array version with a 1 dimensionnal array version, concatenating inner arrays. My question is : how can I still return a reference to a sub array of data ?

class Blah
{
    float[] data;
    int rows;

    public float[] GetDataReference(int index)
    {
        // Return a reference data from offset i to offset j;
    }
}

I was thinking that unsafe and pointers stuff may be of use, is it doable ?

© Stack Overflow or respective owner

Related posts about c#

Related posts about unsafe