Reading and Writing value within the winform C# | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Reading and Writing value within the winform C#

I'm trying to design a really simple winform, and I want to write and read a common public variable within the program, for example record how many time you clicked button. For a simple variable text file is good to pick, but what if there are more? xml, file json file, text file, which is used for storing user change variable? And how it has been used to read and write into the variable we already defined? I've seen something in xml like this:********* <Player1/> <Player1 attack: 500/> *********** Forgive me if my xml expample syntax is wrong.

31st May 2021, 3:01 AM
Yasswecancn
Yasswecancn - avatar
3 Answers
+ 1
The main problem is to define a variable in external file, read and write into that variable.Text isn't good enough because I have to convert everything into the variable and let project parse it before I could use it in program.NEZ
31st May 2021, 4:01 AM
Yasswecancn
Yasswecancn - avatar
+ 1
A variable by definition cannot be persistent, you can only store or retrieve is value. If you want to use plain text file to store the value, parsing for any read operation is mandatory. In your case you can think to overwrite your object whenever you set a property, anyway you don't need to read value back because it is already set in your object, you only need to load it when your program starts. Check this library for store object in Json format. https://www.newtonsoft.com/json/help/html/SerializeWithJsonSerializerToFile.htm And this is the way for read it back. https://www.newtonsoft.com/json/help/html/DeserializeWithJsonSerializerFromFile.htm
31st May 2021, 10:13 PM
Eymerich