locked
to convert an arraylist to an integer array RRS feed

  • Question

  • hi

    i want to convert an arraylist to an integer array.

    my code is below:

    ArrayList ^error=gcnew ArrayList();

    error->add(1);

    error->add(2);

    error->add(3);

    int count=error->Count;

    array<int,1>^ errornumber = gcnew array<int,1>(count);
                   
    errornumber=error->ToArray();

    the error i'm getting this:

     error C2440: '=' : cannot convert from 'cli::array<Type> ^' to 'cli::array<Type> ^'   

     

    can anyone help in this regard please

     

    thanks

     

    Tuesday, October 12, 2010 9:55 AM

Answers

  • On 12/10/2010 11:55, Bujju wrote:

    hi

    i want to convert an arraylist to an integer array.

    my code is below:
    ArrayList ^error=gcnew ArrayList();

    Why don't you just use the more modern (and generic-based) System::Collections::Generic::List<int> instead of old ArrayList?

    System::Collections::Generic::List<int> ^ error = gcnew
    System::Collections::Generic::List<int>;
    
    error->Add(1);
    error->Add(2);
    ...
    
    array<int> ^ errornumber = error->ToArray();
    

     Giovanni

    • Marked as answer by Jesse Jiang Tuesday, October 19, 2010 1:51 AM
    Tuesday, October 12, 2010 10:45 AM