问题
I'm trying to access settings from a settings file(MySettings) that I have created through the SharpDevelop Template:
Setting:
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string s_Username {
get {
return ((string)(this["s_Username"]));
}
set {
this["s_Username"] = value;
}
}
}
Code:
void MainFormLoad(object sender, EventArgs e)
{
MessageBox.Show(AdhesionCharting.Properties.MySettings.s_Username);
}
Error:
'AdhesionCharting.Properties.MySettings' is a 'type', which is not valid in the given context
回答1:
If you look at your MySettings.cs file you will see that the class is not static. There is a Default property which is static that can be used. So your code should be changed to be:
void MainFormLoad(object sender, EventArgs e)
{
MessageBox.Show(AdhesionCharting.Properties.MySettings.Default.s_Username);
}
来源:https://stackoverflow.com/questions/38934422/sharpdevelop-access-resource-file-settings