0

Normally, I can save settings like this:

Properties.Settings.Default.DarkTheme = true;

But how can I use variable as the name?

For example:

string varname = "DarkTheme";
Properties.Settings.Default.{varname} = true; //This is supposed to do the same thing as the codeblock above
user3595338
  • 737
  • 3
  • 11
  • 26
  • 2
    Use reflection, see [duplicate](http://stackoverflow.com/questions/2203545/using-reflection-to-set-a-static-variable-value-before-objects-initialization). :) – CodeCaster May 17 '14 at 14:52
  • 1
    @CodeCaster Could also be a dup for [this](http://stackoverflow.com/questions/619767/set-object-property-using-reflection) – Liam McInroy May 17 '14 at 14:52
  • @Outlaw you're right, `Settings.Default` returns an instance on which you can use reflection: `PropertyInfo prop = Properties.Settings.Default.GetType().GetProperty("DarkTheme", BindingFlags.Public | BindingFlags.Instance); prop.SetValue(Properties.Settings.Default, true, null);`. – CodeCaster May 17 '14 at 14:55

0 Answers0