0

我最近一直在研究我的软件,我一直想知道存储关联数组的最佳方法是什么。

我唯一能想到的就是做这样的事情:

<add key="disks" value="C|1|10,D|2|20,E|1|5,Z|1|3"/>

但这并没有在我的配置文件中提供很多可读性,我希望我的配置文件是可读的,因为它是一个控制台应用程序。

这是因为我编写了一个程序来检查 app.config 文件中指定的磁盘的磁盘空间,但我想要不同磁盘的不同阈值。

你会怎么解决?这是我当前配置文件的一部分。

<!-- DISK FEATURE SETTINGS -->
  <!-- Type 1 is threshold by percentage and type 2 is threshold by a certain limit -->
  <add key="threshold_type" value="1" />
  <add key="threshold_limit" value="0,1" />
  <!-- Space_type defines if you want to limit using kilobytes (1), megabytes (2) or gigabytes (3) if using threshold_type 2 -->
  <add key="space_type" value="3" />
  <!-- Put the disks here delimited by a comma like this: C,D,E -->
  <add key="disks" value="C,D,E,Z"/>
<!-- SERVICE FEATURE SETTINGS -->
  <!-- Put the services here delimited by a comma like this: C,D,E -->
  <add key="services" value="spooler,ekrn,RadeonPro Support Service,TeamViewer6"/>
  <!-- Put this on 1 if you want to log your output to a text file -->
  <add key="logging" value="1"/>

我想对我的 performancecounter 程序使用相同的原理,该程序使用 perfmon 计数器获取一些数据并将其存储在文本文件中。

我希望人们可以在这里帮助我一点:)

4

3 回答 3

4

我建议您创建自己的配置部分。自定义配置提供了更高的可读性和类型安全性。以下是创建自定义配置的链接 http://msdn.microsoft.com/en-us/library/2tw134k3.aspxhttp://haacked.com/archive/2007/03/11/custom-configuration-sections-in -3-easy-steps.aspx(旧的但易于理解)。

于 2012-07-27T05:33:48.197 回答
1

就标准配置机制与 XML 序列化一起使用而言,在 App.config 中存储字典的最佳(以及,恕我直言,明智的)方式是List<KeyValuePair<K,V>>.

于 2012-07-27T05:26:15.883 回答
0

您可能想使用 system.collection 或 List<> 中的 Hashtable

以下是哈希表的一些指针, http://www.dotnetperls.com/hashtable http://www.tutorialspoint.com/csharp/csharp_hashtable.htm

我希望这有帮助!!谢谢 :)

于 2014-06-12T10:56:07.947 回答