我有这样的功能:VB奇变量使用问题,因为文件路径
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中工作,我从来没有见过的错误这种性质之前。这是什么意思,我可以重写函数来获得我想要的?
干杯!如果我可以的话,会接受它:) – YsoL8 2011-05-14 10:34:56
这个错误对我来说似乎相当有用......你不能隐式地将一个Object类型的参数转换(或缩小)为String类型的参数,所以第一个重载是数出来了。而且你不能隐式地将类型为'Object'的参数转换为'System.IO.Stream'类型之一,所以第二次过载被计数出来。现在没有人可以选择! – 2011-05-14 10:42:56
我从来没有处理任何种类的重载之前,所以... – YsoL8 2011-05-14 11:03:56