0

Storing Data

I would like to set up some data parameters that the user inputs and would like to save them and have them referenced in C# as I will be using that in Mono to design and develop a game. Do I save it in a class and use inheritance or is there another method I can use? Some sample code would be nice so I can see how it is set up as well.

8th Jan 2017, 9:36 PM
Levi del Valle (Mizuotaku)
Levi del Valle (Mizuotaku) - avatar
4 odpowiedzi
+ 1
Alright: If you want to store simple Strings like "I love SoloLearn" in a File, you have to use this code: StreamWriter file = new StreamWriter("c:\\file.txt",true); file.WriteLine("Your String"); file.Close(); The boolean value in the Constructor of the StreamWriter sets the flag if you want to append to the file or overwrite it. If the file does not exist, it will be created. If you want to save a complex Object you have to serialize it. This is a bit more complex. Here are some great articles about it: https://msdn.microsoft.com/en-us/library/mt656716.aspx I prefer the XMLSerialization: https://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx
8th Jan 2017, 10:03 PM
Jonas Fallmann
Jonas Fallmann - avatar
0
So... you want to save data on the hard-drive?
8th Jan 2017, 9:38 PM
Jonas Fallmann
Jonas Fallmann - avatar
0
In the program's savefiles and how do I make those.
8th Jan 2017, 9:50 PM
Levi del Valle (Mizuotaku)
Levi del Valle (Mizuotaku) - avatar
0
Thank you very much, still a new learner in C# but getting used it, before I go learn another lang, might go C++ as it is a sister language.
8th Jan 2017, 10:10 PM
Levi del Valle (Mizuotaku)
Levi del Valle (Mizuotaku) - avatar