This is an offline app And I am simply trying to write back to to the Settings.settings file.
In my project under Properties in the file named Settings.settings I add
Name: User, Type: string, Scope:User, Value:Default
After that in my App.xaml.cs file I attempt to read from and write to that value. I have no issue reading from that value, but it seems that it is not even an option to write back.
Here is my code:
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
namespace StrainTracker
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
string userName= StrainTracker.Properties.Settings.Default.User;
StrainTracker.Properties.Settings.Default.User = "SomethingSilly"; //line 16
StrainTracker.Properties.Settings.Default.Save(); //line 17
}
}
Here are the errors generated by visual studio.
Error 1 Invalid token '=' in class, struct, or interface member declaration ..\Projects\StrainTracker\StrainTracker\App.xaml.cs 16 63 StrainTracker
Error 2 Invalid token '(' in class, struct, or interface member declaration ..\Projects\StrainTracker\StrainTracker\App.xaml.cs 17 55 StrainTracker
Error 3 'StrainTracker.Properties.Settings.Default' is a 'property' but is used like a 'type' ..\Projects\StrainTracker\StrainTracker\App.xaml.cs 16 43 StrainTracker
Error 4 'StrainTracker.Properties.Settings.Default' is a 'property' but is used like a 'type' ..\Projects\StrainTracker\StrainTracker\App.xaml.cs 17 43 StrainTracker
I can not for the life of me figure out what the issue is. Any thoughts?
Consider placing the code inside a constructor or some method: