Variable 'fs' hides variable in an enclosing block
vb.net, visual-studio-2010, xna
Solution
You are declaring the variable, then using that same variable name in a `Using` block (which tries to declare it again).
Change it to this:
Public Sub CreateScore()
' open isolated storage, and write the savefile.
Using fs As IsolateStorageFileStream = 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
Problem
I am currently using the following code: ``` 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 ``` However the fs after using is underlined in blue and gives the error Variable 'fs' hides variable in an enclosing block. Does anybody know how i can fix this?