C
C#2y ago
Immusama

❔ How do I store data properly?

So I'm streaming on Twitch and I have a program called Streamer.Bot which allows me to use C# to execute code. I have a very basic and limited understanding about C# and coding in general ~ what I'm trying to do is store my viewers data in specific categories I define myself. The main problem I'm having is understanding how to store the acquired data into a file (I haven't figured out another way yet, either .txt, .csv or .ini). An example how I'm imagining it: .ini file is named after my viewer's username in a folder with all the others:
[section1]
key1="value"
key2="value"

[section2]
key1="value"
key2="value"
[section1]
key1="value"
key2="value"

[section2]
key1="value"
key2="value"
I wanna be able to read it and override specific keys if I so desire. (Most of it is automatic) To sum it up, I know how to write it into a file but I don't know how to format it properly and check for specific sections and key+values and override them.
4 Replies
Thinker
Thinker2y ago
You probably wanna use a JSON file for this So perhaps you have two categories, regular and super, then your JSON could look like this
{
"regular": [
"user1",
"user2",
"user3"
],
"super": [
"user4",
"user5"
]
}
{
"regular": [
"user1",
"user2",
"user3"
],
"super": [
"user4",
"user5"
]
}
I don't really know what you want, but JSON is very flexible, and it's very easy to convert JSON to and from C# data structures.
Immusama
ImmusamaOP2y ago
Oh yea, thats seems like exactly what Im looking for. I will look into it! Thank you
Angius
Angius2y ago
Also, C# has a built-in way to serialize and deserialize JSON So that's one dependency less that you'd need to handle TOML or some other format
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server