I need to read a string from Settings in my C# program. Here is what I did:
- Right-click on my project and selected "Properties".
- Clicked on the "Settings" tab.
- Created a default settings file by clicking on "This project does not contain a default settings file. Click here to create one."
- Added a new setting with the name=ASHost, type=string, Scope=Application开发者_开发问答, Value=some. The access modifier for the settings file is "Internal".
- I clicked on "View Code". Then looked at the namespace which is SI.AS.CommonLogic.ErrorUtils.Properties.
But when I go to my class in the same project and write:
SI.AS.CommonLogic.ErrorUtils.Properties.Settings.
Then this is as far as IntelliSense will autocomplete. I want it to read/write:
SI.AS.CommonLogic.ErrorUtils.Properties.Settings.ASHost
What am I missing?
note: IntelliSense can't see "Settings" on its own.
update "Default doesn't appear with IntelliSense after Settings. Typing
SI.AS.CommonLogic.ErrorUtils.Properties.Settings.Default.ASHost
manually gives an Invalid token error.
solved
Now IntelliSense finally showed Default.ASHost. I changed the "Access Modifier" under the settings tab to "Public".
- You change the scope to
User
. Application settings are ReadyOnly. The settings are at:
SI.AS.CommonLogic.ErrorUtils.Properties.Settings.Default.ASHost
SI.AS.CommonLogic.ErrorUtils.Properties.Settings.Default.ASHost
Almost there. You missed Default
.
Properties.Settings.Default.<Your_Setting_Name>
Just as an addition to what everyone else has said, the Settings
class is generated at compile time. So you will need to compile at least once after adding new settings before the setting will show up in Intellisense.
精彩评论