我有这个功能:
Function WriteTextToFile(ByVal data)
Dim file As New System.IO.StreamWriter("E:\storage.txt")
file.WriteLine(data)
file.Close()
End Function
我一直在尝试调整它,以便文件路径成为我可以传递的变量以允许多个存储文件。像这样的东西:
Function AppendTextToFile(ByVal data, ByVal path)
Dim file As New System.IO.StreamWriter(path, True)
file.WriteLine(data)
file.Close()
End Function
然而,虽然功能 1 有效,但功能 2 却没有——我得到了这个无益的错误:
Overload resolution failed because no accessible 'New' can be called without a narrowing conversion:
'Public Sub New(path As String)': Argument matching parameter 'path' narrows from 'Object' to 'String'.
'Public Sub New(stream As System.IO.Stream)': Argument matching parameter 'stream' narrows from 'Object' to 'System.IO.Stream'. C:\Users\films ratings\films ratings\Form1.vb
我通常在 PHP 中工作,以前从未见过这种性质的错误。这是什么意思,我可以重新编写函数以获得我想要的吗?