我有下面的代码需要我转换的字符数组字符串数组,但我得到了以下错误:Option Strict On disallows implicit conversions from '1-dimensional array of Char' to 'System.Collections.Generic.IEnumerable(Of String)'
如何转换的字符数组字符串数组
Dim lst As New List(Of String)
lst.AddRange(IO.Path.GetInvalidPathChars())
lst.AddRange(IO.Path.GetInvalidFileNameChars())
lst.Add("&")
lst.Add("-")
lst.Add(" ")
Dim sbNewName As New StringBuilder(orignalName)
For i As Integer = 0 To lst.Count - 1
sbNewName.Replace(lst(i), "_")
Next
Return sbNewName.ToString
我试图用通过转换器Array.ConvertAll,但找不到一个好例子,我可以使用循环,但认为会有更好的方法。谁能帮忙?
这也是一种选择。这里是VB语法:lst.AddRange(Path.GetInvalidPathChars()。Select(Function(c)c.ToString())) lst.AddRange(Path.GetInvalidFileNameChars()。Select(Function(c)c.ToString ))) – NYSystemsAnalyst
谢谢,对不起,我没有提到代码库.Net 2.0 –
@MrShoubs,添加了非Linq的答案。 –