convert object[] to ArrayList? (C#)

Is there way to convert 
object[] coll 
to ArrayList
Maybe somebody knows


Answer this question

convert object[] to ArrayList? (C#)

  • DarcyThomas

    <i>> as far as I know the array doesn't implment System.Collections.ICollection ... </i>

    Yes, it does. So you can just use:

    object[] o = ...
    ArrayList a = new ArrayList(o);

  • JACorona

    how about:

    private ArrayList ObjectToArraylist(object[] coll)
    {
         ArrayList al = new ArrayList()
         for (int i = 0; i < coll.Length; i++)
             al.Add(coll[i]);
         return al;
    }

    note that this is adhockly coded, and so untested, but this is what I'ld try.

  • avidal

    as far as I know the array doesn't implment System.Collections.ICollection, so you can't initialize the arrayList automatically

    You can get an array, but you can't do this automatically I believe - however, this is just my opinion that it isn't possible, and that you would have to loop through and add each item.

    Very interesting question...

  • convert object[] to ArrayList? (C#)