我目前使用以下代碼:變量「FS」隱藏變量在封閉塊
Public Sub CreateScore()
' open isolated storage, and write the savefile.
Dim fs As IsolatedStorageFileStream = Nothing
Using fs = savegameStorage.CreateFile("Score")
If fs IsNot Nothing Then
' just overwrite the existing info for this example.
Dim bytes As Byte() = System.BitConverter.GetBytes(Scorecount)
fs.Write(bytes, 0, bytes.Length)
End If
End Using
End Sub
然而,使用後的FS在藍色用下劃線表示,並給出了誤差變量「FS」隱藏變量在一個封閉的塊。
有誰知道我該如何解決這個問題?
嘗試'使用FS作爲IsolatedStorageFileStream = savegameStorage.CreateFile( 「分數」)'和擺脫DIM語句。你有2個版本的FS,但我不確定ISO是如何工作的。 – Plutonix
Using語句將在到達塊的末尾時處理該變量。但是,既然您之前已經聲明過,該塊不能這樣做。您需要在Using語句本身中將該變量聲明爲Plutonix和Jon Egerton所示。 fs變量只會被限制在Using塊中,因此可以自動處理。 –