c# jagged array getter and setter -


i have a:

private bool[][] field {     { return allfields[allfields.count - 1]; }     set { allfields.add(value); generation++; } } 

and a:

if (field[x][y]) {     field[x][y] = false; } else {     field[x][y] = true; } 

the if-clause seems working setter not called in way while setting... there idea of how solve (e.g. better setter) or @ least reason problem?

thanks help

p.s.:

field = nextfield.clone() bool[][]; 

is calling setter...

a better approach use indexer property public accessor array

class boolarray {    public bool this[int raw, int column]    {               {            // access internal jugged array             if (_data[raw] == null)            {                return false;            }             return _data[raw][column];           }         set        {           if (_data[raw] == null)           {              _data[raw] = new bool[columns];           }            _data[raw][column] = value;         }     }     // using jugged array storage    private bool _data[][];    ... } 

Comments