c# - How to use ConfigurationManager -


i want use app.config storing setting. tried use next code getting parameter config file.

private string getsettingvalue(string paramname) {     return string.format(configurationmanager.appsettings[paramname]); } 

i added system.configuration (i used separate class), , in app.config file have:

<?xml version="1.0" encoding="utf-8" ?> <configuration>   <startup>      <supportedruntime version="v4.0" sku=".netframework,version=v4.5" />   </startup>   <appsettings>     <add key ="key1" value ="sample" />   </appsettings> </configuration> 

but got error while trying use configurationmanager - configurationmanager can't exist in such context, added system.configuration. or did miss something?

edit:

class config (full view)

using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; using system.configuration;  namespace browser {     class configfile     {         private string getsettingvalue(string paramname)         {             return string.format(configurationmanager.appsettings[paramname]);         }     } } 

edit2

add how looks

enter image description here

this means problem not during using configurationmanger before - program "says" "doesn't know such element" understand error - "element configurationmanager" doesn't exist in such context"

edit3

enter image description here

edit 4

enter image description here

okay, took me while see this, there's not way compiles:

return string.(configurationmanager.appsettings[paramname]); 

you're not calling method on string type. this:

return configurationmanager.appsettings[paramname]; 

the appsettings kvp returns string. if name doesn't exist, return null.


based on edit have not yet added reference system.configuration assembly project you're working in.


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -