Search code examples
vala

Using get[int index] and set[int index] to update values in an array


I am trying to provide a way to update a value inside an array in vala, for example myClass.Channels[10]=15, however, I can't find a way to do this in vala. The following works in C#, and I would have assumed that vala was similar.

private int[] _channels;

public int[] Channels
{
    get[int index]
    {
        return _channels[index];
    }
    set[int index]
    {
        _channels[index] = value;
    }
}

Does anybody know if a way of doing this exists?


Solution

  • Vala supports Indexers, see http://live.gnome.org/Vala/ValaForCSharpProgrammers#Indexers

    It can only be used on class, not on arrays.

    If that's really useful for you, you should open a bug (and even provide a patch!)