Mehdi LAMRANI
Mehdi LAMRANI

Reputation: 11597

C# Console Application - Edit User Setting at runtime

I had a Winforms App with a propertyGrid to let the user edit his settings.
How to achieve the same goal whithin a Console Application?

ANSWER
Thanks to those who answered. Here is a synthetic code based on a few answers :

Console.WriteLine("Choose user settings to setup");
Console.WriteLine("User setting1: press 1");
Console.WriteLine("User setting2: press 2");

string line = Console.ReadLine();
int code = int.Parse(line);
swicth(code) 
{
   case 1: 
    Settings.Default.MyProperty = line ;
    Settings.Default.Save();
    break;

   case 2: 
    ...
 }

Upvotes: 3

Views: 1839

Answers (3)

Eino N.
Eino N.

Reputation: 473

Settings.Default.MyProperty1 = "some value";
Settings.Default.MyProperty2 = 2;
Settings.Default.Save();

Upvotes: 3

Catalin Serafimescu
Catalin Serafimescu

Reputation: 369

Console applications does not have an User Interface, by definition (though you can force display of Windows Forms). You need to rethink your solution. Maybe you want to use app.config (XYZ.exe.config) or a separate configuration file. BTW, you can edit application settings file from code.

Upvotes: 2

Tigran
Tigran

Reputation: 62256

You should prompt the user about user settings. Something like this:

Console.WriteLine("Choose user settings to setup");
Console.WriteLine("User setting1: press 1");
Console.WriteLine("User setting2: press 2");
....
...
string line = Console.ReadLine();
int code = int.Parse(line);
swicth(code) 
{
   case 1: 
     ....
    .....
   case 2: 
}

After save changes in XML file.

If it's not you're asking for, please clarify.

Upvotes: 2

Related Questions