简体   繁体   中英

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM