代码一:存储变量和常量的Class.
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
1
using System;
2
using System.Collections.Generic;
3
using System.Text;
4
using System.Collections.Specialized;
5![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
6
namespace TestTemp.ConsoleApp
7![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
8
public class Config
9![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
10![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
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![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
14
for (int i = 0; i < keys.Length; i++)
15![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
16![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
17
tmp.Add(keys[i], keys[i].ToUpper());
18
}
19
}
20
public int Count
21![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
22
get
23![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
24
return tmp.Keys.Count;
25
}
26
}
27![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
28
public string this[string index]
29![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
30
get
31![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
32
if (tmp.ContainsKey(index))
33![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
34
return tmp[index];
35
}
36![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
else
{ return ""; }
37![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
38
}
39
}
40![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
41
}
42
}
43![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
代码二,实现静态访问:
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
1
using System;
2
using System.Collections.Generic;
3
using System.Text;
4![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
namespace TestTemp.ConsoleApp
6![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
7
public static class Test
8![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
9
public static Config AppSettings
10![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
11![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return new Config(); }
12
}
13
}
14
}
15![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
代码三,使用:
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
1
using System;
2
using System.Collections.Generic;
3
using System.Text;
4
using System.IO;
5
using System.Management;
6
using System.Text.RegularExpressions;
7![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
8![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
9
namespace TestTemp.ConsoleApp
10![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
11
class Program
12![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
13![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
14
static void Main(string[] args)
15![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
16
17
Console.Write(Test.AppSettings["Name"]);
18
Console.Read();
19
}
20
}
21
}
很简单,找了n久的资料都没有具体说实现静态索引的BT办法.只能通过这样实现