[英]element of array to string in Visual Basic
I have this code written in Visual basic: 我用Visual Basic编写了以下代码:
Dim directory As String = Application.StartupPath()
Dim dirinfo As New DirectoryInfo(directory)
Dim filesnatt As String() = dirinfo.GetFiles("*.nat")
Dim filenatt As String
For Each filenatt In filesnatt
Dim filenat As String = Str(filenatt)
Using re As StreamReader = New StreamReader(filenat)
Dim val As String = re.ReadLine()
If val.Contains(TextBox2.Text) Then
Dim a1 As String = filenat
a1 = a1.Remove(".nat")
ComboBox2.Items.Add(a1)
End If
End Using
Next
But I get this error: Value of '1 - dimensional array of System.IO.FileInfo' cannot be converted to '1 - dimensional array of String' because 'System.IO.FileInfo' is not derived from 'String'. 但是我收到此错误:无法将'System.IO.FileInfo的1维数组的值转换为String的1维数组,因为'System.IO.FileInfo'不是从'String'派生的。
How to fix that? 如何解决?
thats because GetFiles
returns FileInfo
instead of String
change 那就是因为
GetFiles
返回FileInfo
而不是String
更改
Dim filesnatt as String() to Dim filesnatt as FileInfo()
and 和
Dim filenatt as String to Dim filenatt as FileInfo
and in the For Each
loop use 并在
For Each
循环中使用
Dim filenat as String = filenatt.FullName
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.