I’m making a .net console app that is an arena discord bot, and on bot startup, there will be a lot of Character data loaded from a JSON file (I’m porting a Unity app and this correlates to all the ScriptableObject data). For now, I’d like to just keep this character data in memory until eventually moving it to a DB. I’m wondering what best practice is when storing this type of global data in a console app. In looking at example code, I see examples of a public class with static variables storing the data and static methods retrieving it. Here’s an example of what I’m planning to do. Is this a typical approach?
public sealed class CharacterData
{
private static List<Character> characters = new();
public static void AddCharacterData(Character character)
{
characters.Add(character);
}
public static Character GetCharacterData(Guid guid)
{
return characters.Find(x => x.id == guid);
}
}
public class Character
{
public Guid id = Guid.NewGuid();
public string myName = "";
public int level = 1;
}
It’s working like this, I’m just looking for best practice advice.
Sean Gailey is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.