0

I need to save to a different setting based on the input string. Why will this line not work?

Properties.Settings.Default + colorOptionNametoSave = selectedIndexString;
Properties.Settings.Default.Save();

Where the colorOptionNametoSave is a different color setting and the selectedIndexString is the value to save. However I get the message:

Error 2: The left-hand side of an assignment must be a variable, property or indexer.

The only work around I can think of is a switch statement, but I have a lot of colors so that would be really long. Any ideas on a more efficient solution?

1 Answer 1

2

if/else or a switch is what you are looking for.

You cannot concatenate a variable name!

So a solution for you would be something like this ( if colorOptionNametoSave is a string ):

if(colorOptionNametoSave == "Blue")
{
    Properties.Settings.Default.Blue = selectedIndexString;
}
else if(colorOptionNametoSave == "Red")
{
    Properties.Settings.Default.Red = selectedIndexString;
}
1
  • arg ok i was just hoping for a more elegant method. will start writing the 300+ case switch block then....haha. Jul 6, 2012 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.