Saturday, June 28, 2014

Object reference not set to an instance of an object. for array?

This is because you have Initialized and Array of Hashset(valuesOfKey),and these values are not Initialize.They are Null.Except the First Element valueofKey[0]=a["A].So if you try to access other than the First Element you will get the error Object Reference not set to instance.Instead you can try to initialize the valuesofkey with some default value and then try to access the elements.


May be something like this


int mydefaultvalue=0;


for(int i=0;i<sq.Length;i++)


{


valueofKey[i]=mydefaultvalue;


}


and then...


valueOfKey[0]= a["A"]




No comments:

Post a Comment