locked
Array:Resize not working for me? RRS feed

  • Question

  • Hi I have a class (ref class Device) which has an array<MyObj^>^ Registers variable initialized as gcnew array<MyObject^>(10).

    I then do Array::Resize(this->Device->Registers, newSize);

    Then I print the new array size (using ->Length on the arrary) on a textBox. I am surprised to see the array size has not changed?? What am I doing wrong?

     

     

    Monday, September 26, 2011 6:49 AM

Answers

  • thanks guys, I am sorry I didnt provide code sample...it had become a rather long code...so I avoided having to paste it all here, no one will have read it.

    I ended up using List instead of array. It works fine now with List.

     

    Thursday, September 29, 2011 9:46 PM

All replies

  • >What am I doing wrong?

    That's like calling a garage and asking what's wrong
    with my car, because it doesn't run right. How can we
    say without seeing the *actual* code? There are many
    possibilities for bugs.

    - Wayne
    Monday, September 26, 2011 2:33 PM
  • Hi ,

    I have tried as follows :

    First , I created a ref class named MyObject  and  later on created another ref class named Device containing an array <MyObject^>^ Registers and initialized the array in the constructor ,  just as  Registers=gcnew array<MyObject^>(10);.

    Then ,  I add one button in the form which also has a textBox ,  and add the follow codes in the button's click event :

    Device^ device=gcnew Device();
    int newsize=20;
    Array::Resize(device->Registers , newsize);
    this->textBox1->Text=device->Registers->Length.ToString();
    
    

    at last I  build and run the project . After clicking  the button , the text of the textBox is changed to 20 .

    Please check your code and try it again .

    If this can't help , please let me know the version of your Visual Studio and operating system .

    If you have any concerns , please feel free to let me know.

    Best regards ,

    Tuesday, September 27, 2011 3:12 AM
  • thanks guys, I am sorry I didnt provide code sample...it had become a rather long code...so I avoided having to paste it all here, no one will have read it.

    I ended up using List instead of array. It works fine now with List.

     

    Thursday, September 29, 2011 9:46 PM