开发者

How do I read settings?

开发者 https://www.devze.com 2023-02-20 13:12 出处:网络
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\".

I need to read a string from Settings in my C# program. Here is what I did:

  1. Right-click on my project and selected "Properties".
  2. Clicked on the "Settings" tab.
  3. Created a default settings file by clicking on "This project does not contain a default settings file. Click here to create one."
  4. Added a new setting with the name=ASHost, type=string, Scope=Application开发者_开发问答, Value=some. The access modifier for the settings file is "Internal".
  5. 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".


  1. You change the scope to User. Application settings are ReadyOnly.
  2. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消