本文整理汇总了C#中System.Configuration.AppSettingsReader.GetValue方法的典型用法代码示例。如果您正苦于以下问题:C# AppSettingsReader.GetValue方法的具体用法?C# AppSettingsReader.GetValue怎么用?C# AppSettingsReader.GetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。
在下文中一共展示了AppSettingsReader.GetValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DisplayAppSettings
static void DisplayAppSettings()
{
try
{
var reader = new AppSettingsReader();
NameValueCollection appSettings = ConfigurationManager.AppSettings;
for (int i = 0; i < appSettings.Count; i++)
{
string key = appSettings.GetKey(i);
string value = (string)reader.GetValue(key, typeof(string));
Console.WriteLine("Key : {0} Value: {1}", key, value);
}
}
catch (ConfigurationErrorsException e)
{
Console.WriteLine("[DisplayAppSettings: {0}]", e.ToString());
}
}
示例2: Main
//引入命名空间
using System;
using System.Configuration;
class MainClass
{
static void Main(string[] args)
{
AppSettingsReader ar = new AppSettingsReader();
Console.WriteLine("Here is your conn string");
Console.WriteLine(ar.GetValue("appConStr", typeof(string)));
Console.WriteLine();
int numbOfTimes = (int)ar.GetValue("intValue", typeof(int));
for(int i = 0; i < numbOfTimes; i++)
Console.WriteLine("Yo!");
}
}
/*
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="appConStr" value="server=localhost;uid=sa;pwd=;database=Cars" />
<add key="intValue" value="4" />
</appSettings>
</configuration>
*/