lundi 16 mai 2016

C# Access Pattern

I need a class to help me access a chunk of memory

So far I have this

class ABSet
{
    private byte[] _raw;
    public ABSet(byte[] RawData)
    {
        _raw=RawData;
    }
    public double A
    {
        get
        {
            return BitConverter.ToDouble(_raw, 2);
        }
     }
     public double B
     {
         get
         {
             return BitConverter.ToDouble(_raw, 10);
         }
     }
}

Now I would like to do something like this

class ABSetCollection
{
    private byte[] _raw;
    public ABSetCollcetion(byte[] RawData)
    {
        _raw=RawData;
    }
    public ABSet this[int index]
    {
        get
        {
            // This Part Is What I Want To Figure Out
        }
     } 
}

I know I could put return new ABSet(_raw); but I feel like there must be a solution that requires less dynamic allocation.

P.S. The reason I want to use properties is because I am binding to them in my GUI

Aucun commentaire:

Enregistrer un commentaire