Last active
December 13, 2015 18:19
-
-
Save caglartoklu/4954533 to your computer and use it in GitHub Desktop.
Simple app.config usage in C#. #cs #config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8" ?> | |
<configuration> | |
<startup> | |
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> | |
</startup> | |
<appSettings> | |
<add key="one" value="1"/> | |
<add key="two" value="2"/> | |
<add key="three" value="3"/> | |
<add key="four" value="4"/> | |
</appSettings> | |
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace myapp | |
{ | |
// Make sure you add a reference to System.Configuration.dll. | |
// http://msdn.microsoft.com/en-us/library/system.configuration.appsettingsreader.aspx | |
using System; | |
using System.Collections.Specialized; | |
using System.Configuration; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
AppSettingsReader reader = new AppSettingsReader(); | |
NameValueCollection appSettings = ConfigurationManager.AppSettings; | |
Console.WriteLine(appSettings["two"]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment