0

i need a config file for my applications and i've looked through internet without really finding what I want, I want to set my config to a var and use it like config.somethingInTheConfig. I tried some things but it didn't work, the config file :

{
"id": 00,
"somethings": true,
"yes": "idkjustsomething"
}

the Config class :

class Config
{
    public static int id { get; set; }
    public static bool somethings { get; set; }
    public static string yes { get; set; }
}

Code to read it

using (StreamReader streamReader = new StreamReader("config.json"))
        {
            string json = streamReader.ReadToEnd();
            Config config = JsonConvert.DeserializeObject<Config>(json);
            Console.WriteLine(config.id);
        }

I want it to show the id in the config in the console but it doesn't work nd gives me an error, anyone could help ?

1 Answers1

0

The properties are marked static. JsonConvert will not be able to read values into the static properties. And since you are not defining values for them at design time, the properties will be set to their default values unless you manually change them.

afroze9
  • 13
  • 1
  • 4