shtkuh
shtkuh

Reputation: 459

Pass ArrayList to web service in C#

I have web service that should receive param ArrayList

[WebMethod] 
public void SelectPatches(ArrayList selectedPatches){}

But when I call this method from client Visual Studio return error:

Cannot convert from 'System.Collections.ArrayList' to 'object[]'

Is it possible to pass parameter with type ArrayList to Web Service?

Upvotes: 0

Views: 5009

Answers (2)

abatishchev
abatishchev

Reputation: 100348

Don't use non-generic collections. Use generic, at least List<object>.

Web method should accept array of any type, thus use ToArray() extension method.

Upvotes: 3

Polynomial
Polynomial

Reputation: 28336

You can use arrayList.ToArray() (MSDN) to convert an ArrayList to an object[].

You can also use arrayList.ToArray(Type) (MSDN) to convert an ArrayList to an array of the specified type, instead of having to cast each element individually.

Upvotes: 1

Related Questions