Compiler warning: null reference exception

前端 未结 3 802
盖世英雄少女心
盖世英雄少女心 2021-01-18 14:39

I have the following code in Visual Studio 2005.

    Dim OutFile As System.IO.StreamWriter
    Try
        OutFile = New System.IO.StreamWriter(Filename)
            


        
3条回答
  •  时光说笑
    2021-01-18 15:12

    Dim OutFile As System.IO.StreamWriter
    OutFile = Nothing
    Try
        OutFile = New System.IO.StreamWriter(Filename)
       // Do stuff with OutFile
    Catch Ex As Exception
       // Handle Exception
    Finally
       If OutFile IsNot Nothing Then OutFile.Close()
    End Try
    

    Similar to C# error: Use of unassigned local variable

提交回复
热议问题