Aleodor

Hi there... i am developing an application for smart devices.

In my code i am consuming a webservice which returns me an arraylist.

In my part of the program i want to use the returned arraylist through a list of operations...bla bla

But i cannot assign the returned arraylist to another arraylist (which i can use without calling again the webservice) from the program, and i am receiving this error:

"Cannot convert type 'object[]' to 'System.Collections.ArrayList' ".

i tried casting something like Arraylist a= (Arraylist)....., but did not work still receiving same error.

Any suggestions



Re: Smart Devices VB and C# Projects Convert object to arraylist

Ilya Tumanov

It looks like your WS returns you an array of objects, not an ArrayList. If you need an ArrayList you'd need to construct it:

C#:

ArrayList a = new ArrayList(YourObjectArrayHere);

VB:

Dim a As new ArrayList(YourObjectArrayHere)






Re: Smart Devices VB and C# Projects Convert object to arraylist

Aleodor

thx... the return was ok but the declaration of the new arraylist was pathetic...



Re: Smart Devices VB and C# Projects Convert object to arraylist

Raaja.K

How to convert arraylist to object array Thanks!





Re: Smart Devices VB and C# Projects Convert object to arraylist

Raaja.K

I got it.

MyClass[] myClassArray = (MyClass[])myArrayList.ToArray(typeof(MyClass))







Re: Smart Devices VB and C# Projects Convert object to arraylist

Hemalatha G

Hi Ilya and Raaja,

Thanks a lot...it Works :)





Re: Smart Devices VB and C# Projects Convert object to arraylist

AAC, Inc.

I was experiencing the same issue with the ArrayList, I tried type casting but that didn't work. Your solution to create a new ArrayList from the object solved the error. Thanks for the tip.