Empty an Array

Hello,

I have an array that gets modified everytime a button is pressed. What I need is to empty out the array at the beginning of the button pressed event.

arrayList[ ] arrayList1 = new arrayList[cntMax]; //this is how it is defined outside of the buttonpressed fuction

arrayList1[ ] = null; //this is the code i have inside the beginning of the button pressed function

arrayIndex = 0;

I get an error with the second statement.



Answer this question

Empty an Array

  • ahmedilyas

    arrayList[ ] arrayList1 = new arrayList[cntMax];  //this is how it is defined outside of the buttonpressed fuction


    arrayList[ ] arrayList1;     // This is the declaration
     


    arrayList1 = new arrayList[cntMax];  //this is the assignment
     

    You can do both on one line (and often it's the best route), but for you purposes, you want to do them separately.  Do the declaration outside the method, and the assignment inside.  That's all you need to do.

     



  • manuel0081

    why don't you just create a new instance of the array

    arrayList1 = new arrayList1[length];

    also I could be confused but are you using the standard .NET ArrayList() collection or is this your own arrayList[] collection



  • Empty an Array