我收到可选参数的错误,它说“需要常量表达式”
我该如何解决这个问题?
Private Function Write_Text_To_File(ByVal Text_File As String, _
ByVal Text As String, _
ByVal Append_Text As Boolean, _
Optional Encoding As System.Text.Encoding = System.Text.Encoding.Default) As Boolean
Try : Using TextFile As New IO.StreamWriter(Text_File, Append_Text, Encoding) : TextFile.WriteLine(Text) : End Using
Return True
Catch ex As Exception
'Return False
Throw New Exception(ex.Message)
End Try
End Function
更新:
解决方案
#Region " Write Text to File "
' [ Write Text to File Function ]
'
' // By Elektro H@cker
'
' Examples :
'
' Write_Text_To_File("C:\Test.txt", "Text", False)
' Write_Text_To_File("C:\Test.txt", "Text", True, System.Text.Encoding.UTF8)
Private Function Write_Text_To_File(ByVal Text_File As String, _
ByVal Text As String, _
ByVal Append_Text As Boolean, _
Optional Encoding As System.Text.Encoding = Nothing) As Boolean
Try
If Encoding Is Nothing Then Encoding = System.Text.Encoding.Default
Using TextFile As New IO.StreamWriter(Text_File, Append_Text, Encoding) : TextFile.WriteLine(Text) : End Using
Return True
Catch ex As Exception
'Return False
Throw New Exception(ex.Message)
End Try
End Function
#End Region