日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

简单实现ConfigurationManager.AppSettings[]效果存储系统变量

發(fā)布時(shí)間:2023/11/27 生活经验 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 简单实现ConfigurationManager.AppSettings[]效果存储系统变量 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
代碼一:存儲變量和常量的Class.
Code
?1using?System;
?2using?System.Collections.Generic;
?3using?System.Text;
?4using?System.Collections.Specialized;
?5
?6namespace?TestTemp.ConsoleApp
?7{
?8????public?class?Config
?9????{
10????????string[]?keys?=?new?string[]?{?"Name",?"Age",?"Location",?"Email",?"Key",?"One",?"Two",?"Three",?"Four"?};
11????????Dictionary<string,?string>?tmp?=?new?Dictionary<string,?string>();
12????????public?Config()
13????????{
14????????????for?(int?i?=?0;?i?<?keys.Length;?i++)
15????????????{
16
17????????????????tmp.Add(keys[i],?keys[i].ToUpper());
18????????????}

19????????}

20????????public?int?Count
21????????{
22????????????get
23????????????{
24????????????????return?tmp.Keys.Count;
25????????????}

26????????}

27
28????????public?string?this[string?index]
29????????{
30????????????get
31????????????{
32????????????????if?(tmp.ContainsKey(index))
33????????????????{
34????????????????????return?tmp[index];
35????????????????}

36????????????????else?{?return?"";?}
37
38????????????}

39????????}

40
41????}

42}

43
代碼二,實(shí)現(xiàn)靜態(tài)訪問:
Code
?1using?System;
?2using?System.Collections.Generic;
?3using?System.Text;
?4
?5namespace?TestTemp.ConsoleApp
?6{
?7????public?static?class?Test
?8????{
?9????????public?static?Config?AppSettings
10????????{
11????????????get?{?return?new?Config();?}
12????????}

13????}

14}

15
代碼三,使用:
Code
?1using?System;
?2using?System.Collections.Generic;
?3using?System.Text;
?4using?System.IO;
?5using?System.Management;
?6using?System.Text.RegularExpressions;
?7
?8
?9namespace?TestTemp.ConsoleApp
10{
11????class?Program
12????{
13
14????????static?void?Main(string[]?args)
15????????{
16????????????
17????????????Console.Write(Test.AppSettings["Name"]);
18????????????Console.Read();
19????????}
?
20}

21}

很簡單,找了n久的資料都沒有具體說實(shí)現(xiàn)靜態(tài)索引的BT辦法.只能通過這樣實(shí)現(xiàn)

轉(zhuǎn)載于:https://www.cnblogs.com/cnherman/articles/1197061.html

總結(jié)

以上是生活随笔為你收集整理的简单实现ConfigurationManager.AppSettings[]效果存储系统变量的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。