简体   繁体   中英

Why unable to pass List<string> from static method to non-static method C#

I have a static method like this:

private static void UpdateExportDate(List<string> lstWithdraw, List<string> lstUnit)
    {
        ServiceReference3.PSSWebServiceSoapClient pwssc = new ServiceReference3.PSSWebServiceSoapClient("PSSWebServiceSoap12");
        ((IContextChannel)pwssc.InnerChannel).OperationTimeout = new TimeSpan(2, 0, 0);

        pwssc.UpdateInfo(lstWithdraw, lstUnit);
    }

In another class, I have a non static method like this:

public void UpdateInfo(List<string> lstWithdraw, List<string> lstUnit)
    {
        UvAccountConversion uac = new UvAccountConversion();           
    }

When I run the project, it has an error stated that:

cannot convert from 'System.Collections.Generic.List<string>' to 'string[]'

I have tried to remove the List (which means I only pass 2 strings) and it is successful. However, I want to pass the records as ' List '.

Please help!

The error message itself is "cannot convert from 'System.Collections.Generic.List' to 'string[]'" there is no difference between static and instance methods in terms of parsing parameters.

The error indicates that somewhere you need to have an array instead of a List

A list is not the same as an array, although you can call a method on the list to return an array.

List<string> someList = new List<string>{"a","B","c"};
someList.ToArray(); //string[] containing ["a","B","c"]

尝试List.ToArray()

pwssc.UpdateInfo(lstWithdraw.ToArray(), lstUnit.ToArray());

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