The best overloaded method match for 'string.Join(string, string[])' has some invalid arguments

前端 未结 4 1113
独厮守ぢ
独厮守ぢ 2021-01-22 07:29

I want to extract come text between two tags. The \"txtReadfile\" contains many tags. I want to extract all the text in each occurrence of the tag.

I used the following

相关标签:
4条回答
  • 2021-01-22 07:58

    Try with:

    string output = string.Join(" ", destList.ToArray());
    
    0 讨论(0)
  • 2021-01-22 08:01

    you have to convert it to ToArray()

    string.join(" ",destList.ToArray());
    
    0 讨论(0)
  • 2021-01-22 08:06

    Before .NET 4, the String.Join method only had overloads that took arrays as their second parameter. Support for IEnumerable<string> was only introduced in .NET 4.0.

    // From .NET 2.0:
    Join(String, String[])
    Join(String, String[], Int32, Int32)
    Join(String, Object[])
    
    // From .NET 4.0:
    Join(String, IEnumerable<String>)
    Join<T>(String, IEnumerable<T>)
    

    Thus, if you're targeting an earlier framework, you need to call ToArray on your list to convert it into string[]:

    string output= string.Join(" ", destList.ToArray());
    
    0 讨论(0)
  • 2021-01-22 08:07

    Most likely, you are using .NET 3.5 or below. In this version string.Join only had two overloads.

    You need to convert your list to an array to be able to pass it in this version.

    Simply use the ToArray method of List<T>:

    string.Join(" ", destList.ToArray());
    
    0 讨论(0)
提交回复
热议问题