C#配置文件操作类,供大家参考,具体内容如下
注意添加引用:System.Configuration;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
using System; using System.Collections.Generic; using System.Text; using System.Configuration; namespace DotNet.Utilities.配置文件操作类 { public class ConfigHelper_sufei { /// <summary> /// 根据Key取Value值 /// </summary> /// <param name="key"></param> public static string GetValue( string key) { return ConfigurationManager.AppSettings[key].ToString().Trim(); } /// <summary> /// 根据Key修改Value /// </summary> /// <param name="key">要修改的Key</param> /// <param name="value">要修改为的值</param> public static void SetValue( string key, string value) { ConfigurationManager.AppSettings.Set(key, value); } /// <summary> /// 添加新的Key ,Value键值对 /// </summary> /// <param name="key">Key</param> /// <param name="value">Value</param> public static void Add( string key, string value) { ConfigurationManager.AppSettings.Add(key, value); } /// <summary> /// 根据Key删除项 /// </summary> /// <param name="key">Key</param> public static void Remove( string key) { ConfigurationManager.AppSettings.Remove(key); } } } |
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:http://www.cnblogs.com/Liyuting/p/7054705.html