i have class property capacity, when capacity = 0, object must sets in initial state. method initstate(), because can't create new instance , assignment this. there way use this or way set initial state?
public class test { private int _field1 = -1; private int[] _array; ... public test() : this(0) { } public test(int capacity) { _array = new int[capacity]; } ... public int capacity { { return _array.length; } set { //not working //if(value == 0) = new test(); if(value == 0) initstate(); ... } } //sets fields in default state private void initstate() { _field1 = -1; _array = new int[0]; ... } }
no, can't assign value you're code correct
Comments
Post a Comment