I tried to add elements to the array,but when I tried to, it showed array is null. I was adding an integer to the array from first element, but still got the problem.Can anyone advise?
class unorderedArray
{
public int[] itemArray=null ;
private int numElements=0;
private int maxElements=0;
public unorderedArray(int max)
{
maxElements = max;
int[] itemArray=new int[maxElements] ;
}
public int[] getItemArray()
{
return itemArray;
}
public bool addLast(int item)
{
if (numElements < maxElements)
{
itemArray[numElements] = item;
numElements++;
}
return true;
}
}
class Program
{
static void Main(string[] args)
{
unorderedArray aa = new unorderedArray(60);
aa.addLast (4);
aa.addLast(5);
aa.addLast(6);
aa.addLast(8);
aa.addLast(90);
aa.addLast(12);
aa.addLast(77);
aa.printList();
Console.ReadKey();
}
}