Why does this code not write anything (System.IO was already declared in the code earlier for both)...
and why does this code actually write what was told to be written?Code:string selection = "initialsave"; StreamWriter sw = new StreamWriter("C:\\Program Files\\BattleGame\\" + selection + ".txt"); sw.WriteLine("testtesttest");
Code:string selection = "initialsave"; using (StreamWriter sw = new StreamWriter("C:\\Program Files\\BattleGame\\" + selection + ".txt")); { sw.WriteLine("testtesttest"); }
I was writing a game and constantly wondering why my game was never saving. I checked the game and I found that the save files were created but not written to. Why is this?
If you don't use the "using" you have to call sw.Close() or else it wont save.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks