- 浏览: 399515 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (309)
- xaml C# wpf (0)
- scala java inner clas (1)
- Tools UML Eclipse UML2 (1)
- Timer .NET Framework (1)
- perl (6)
- python function paramter (1)
- Python Docstring (1)
- Python how to compare types (1)
- Python (8)
- java (5)
- C# (76)
- C# WPF (0)
- p4 (0)
- WPF (46)
- .net (6)
- xaml (1)
- javascript (40)
- windows (10)
- scala (4)
- winform (1)
- c++ (48)
- tools (12)
- cmd (1)
- os (0)
- CI (0)
- shell (0)
- C (2)
- haskell (49)
- functional (1)
- tool (1)
- gnu (1)
- linux (1)
- kaskell (0)
- svn (0)
- wcf (3)
- android (1)
最新评论
There is an type that is called the StringDictionary, the namespace is System.Collections.Specialized;
the StringDictionary is optmized for both key and value types are string;
What situation will the String dictionary be useful? the StringDictionary will be useful in scenario such as Application configuration;
Below shows the operation that you can apply on the StrnigDictionary; Hopefull it may help you understand the StringDictionary;
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections.Specialized; using System.Collections; namespace StringDictionaryTest { class Program { static void Main(string[] args) { StringDictionary myCol = new StringDictionary(); myCol.Add("red" , "rojo"); myCol.Add("green", "verde"); myCol.Add("blue", "azul"); // Display the contenst of the collection using foreach, this is preferred method Console.WriteLine("Display the elemnts using foreach "); PrintKeysAndValues1(myCol); // Display the contens of the collection using Enumerator Console.WriteLine("Display the elements using the IEnumerator:"); PrintKeysAndValues2(myCol); // Display the contents of the collection using the keys, values, Count and Item properties Console.WriteLine("Display the elements using the Keys, Values, Count and item properties"); PrintKeysAndValues3(myCol); // Copies the StringDictionary to an array with DictionaryEntry elements. DictionaryEntry[] myArr = new DictionaryEntry[myCol.Count]; myCol.CopyTo(myArr, 0); // Displays the values in the array. Console.WriteLine("Displays the elements in the array:"); Console.WriteLine(" KEY VALUE"); for (int i = 0; i < myArr.Length; i++) Console.WriteLine(" {0,-10} {1}", myArr[i].Key, myArr[i].Value); Console.WriteLine(); // Searches for a value. if (myCol.ContainsValue("amarillo")) Console.WriteLine("The collection contains the value \"amarillo\"."); else Console.WriteLine("The collection does not contain the value \"amarillo\"."); Console.WriteLine(); // Searches for a key and deletes it. if (myCol.ContainsKey("green")) myCol.Remove("green"); Console.WriteLine("The collection contains the following elements after removing \"green\":"); PrintKeysAndValues1(myCol); // Clears the entire collection. myCol.Clear(); Console.WriteLine("The collection contains the following elements after it is cleared:"); PrintKeysAndValues1(myCol); } public static void PrintKeysAndValues1(StringDictionary myCol) { Console.WriteLine(" KEY VALUE"); foreach (DictionaryEntry d in myCol) { Console.WriteLine(" {0,-25} {1}", d.Key, d.Value); } Console.WriteLine(); } public static void PrintKeysAndValues2(StringDictionary myCol) { IEnumerator myEnumerator = myCol.GetEnumerator(); DictionaryEntry de; Console.WriteLine(" Key VALUE"); while (myEnumerator.MoveNext()) { de = (DictionaryEntry)myEnumerator.Current; Console.WriteLine(" {0,-25} {1}", de.Key, de.Value); } Console.WriteLine(); } public static void PrintKeysAndValues3(StringDictionary myCol) { string[] myKeys = new String[myCol.Count]; myCol.Keys.CopyTo(myKeys, 0); Console.WriteLine(" INDEX KEY VALUE"); for (int i = 0; i < myCol.Count; i++) { Console.WriteLine(" {0,-5} {1,-25} {2}", i, myKeys[i], myCol[myKeys[i]] ); } Console.WriteLine(); } } }
发表评论
-
wpf - example to enhance ComboBox for AutoComplete
2014-09-19 15:56 1976first let’s see an example ... -
Investigate and troubleshoot possible memory leak issue of .NET application
2014-07-31 10:42 0Hi All, I would like to sh ... -
C# – CoerceValueCallback合并、替换元数据值
2013-08-05 21:59 1925Topic: C# – CoerceValueCallbac ... -
wpf – ListView交替背景色
2013-07-02 20:56 6551Wpf – Alternate background col ... -
C# - 简单介绍TaskScheduler
2013-06-29 17:18 12038标题: C# - 简单介绍TaskSchedulerTit ... -
c# - Get enum from enum attribute
2013-06-27 21:32 1244DescriptionAttribute gives the ... -
C# - PInvoke, gotchas on the RegisterClassEx and the CreateWindowEx
2013-06-24 13:49 2571I get an exception message li ... -
c# - Use PInvoke to create simple win32 Application
2013-06-24 11:59 10946In this post, .net platform h ... -
c# - Linq's Select method as the Map function
2013-06-19 18:47 1287If you comes from a functiona ... -
c# - Tips of Linq expression Any to determine if a collection is Empty
2013-06-19 18:29 938When you are @ the linq expres ... -
myth buster - typeof accepting array of types not acceptable
2013-06-19 17:17 813I have seen from some book whe ... -
windows - trying to create WIN32 application with PInvoke
2013-06-19 14:34 0While it is stupid to do such ... -
WPF - Setting foreground color of Entire window
2013-06-13 16:00 1918You might as well as I would s ... -
WPF - Enhanced TabControl - TabControlEx aka Prerendering TabControl
2013-06-13 13:12 5330As an opening word, let's che ... -
wpf - ControlTemplate and AddLogicChild/RemoveLogicalChild
2013-06-10 15:42 1185Recently I was trying to debug ... -
c# - P/Invoke, DllImport, Marshal Structures and Type conversions
2013-06-05 15:25 1712P/Invoke as in the following q ... -
c# - A study on the NativeWindow - encapsulate window handle and procedure
2013-06-05 14:40 6091NativeWindow gives you a way t ... -
WCF - Notify server when client connects
2013-06-03 18:19 1220It is sometimes very importan ... -
wcf - Debug to enable Server exception in Fault message
2013-06-03 15:47 1091WCF will be able to send back ... -
c# - determine if a type/object is serialzable
2013-05-30 16:35 867In WCF, primitives type are s ...
相关推荐
根据提供的文件信息,本文将详细解释如何使用C#语言通过Windows Management Instrumentation (WMI)接口来获取计算机硬件配置信息。 ### 一、WMI简介 Windows Management Instrumentation(WMI)是Microsoft提供的...
StringDictionary是C#中的一个键值对容器,默认情况下其键不区分大小写。它实现了IDictionary<string, string>接口,提供了键值对的存储和检索功能。 二、NameValueCollection NameValueCollection是C#中的另一个...
- **`foreach` VS `for` 语句**:在大多数情况下,`foreach`循环比`for`循环具有更好的执行效率,因为`foreach`是编译器优化过的,而`for`循环可能需要更多的计算。 - **避免使用 `ArrayList`**:`ArrayList`由于...
在C#编程中,优化代码性能是提升应用程序效率的关键。以下是一些高效C#编码的优化原则,这些原则有助于减少资源消耗,提高代码运行速度。 1. **Foreach VS For 语句**: - 在遍历集合时,`foreach` 通常比 `for` ...
为了提高性能,推荐使用`System.Collections.Specialized.StringCollection`来代替`ArrayList`来存储字符串,因为`StringCollection`是专门为存储字符串设计的,它内部实现了更高效的字符串管理机制。 此外,对于...
2. **选择合适的字典类型**: 使用Hashtable可以提升字典操作的性能,而不是使用其他特定类型的字典,如StringDictionary、NameValueCollection或HybridDictionary。 3. **使用字符串常量**: 声明字符串常量可以减少...
- **使用字符串字典**:使用`StringDictionary`类管理动态内容,使文本更容易翻译。 - **分离UI和逻辑**:遵循MVVM模式,将视图与模型解耦,使本地化工作更专注于资源文件。 - **考虑右到左布局**:对于从右向左...
2. **使用Hashtable代替特定字典类型**: 例如,使用Hashtable替代StringDictionary, NameValueCollection, HybridDictionary等,因为Hashtable在某些情况下有更优的性能表现。 3. **声明字符串常量**: 对于经常使用...
RaiDrive翻译项目 除英语和韩语外,某些语言源文件已初始化,但尚未完全翻译。 请为我们提供非翻译语言的帮助,同时也为我们提供翻译语言的改进。 您的贡献可以通过“请求”记录。...StringDictionary.id.xam
相比于StringDictionary、NameValueCollection等其他字典集合,HashTable在性能上有一定的优势。但要注意,HashTable不是线程安全的,如果在多线程环境下,需要考虑同步机制。 3. **使用字符串常量**: 定义字符串时...
在需要存储大量键值对数据时,使用`HashTable`而非`StringDictionary`、`NameValueCollection`或`HybridCollection`,因为`HashTable`提供了更高的查找效率。 #### 6. 避免不必要的字符串引号 在初始化字符串变量...
泛型集合则是为了提高类型安全性,比如ArrayList的泛型版本List和Hashtable的泛型版本Dictionary, TValue>。泛型集合能够确保在编译时进行类型检查,避免了运行时的类型转换和潜在的异常。 **专用集合**则针对特定...
10.3.2 StringCollection、StringDictionary和NameValueCollection 295 10.3.3 BitArray 295 10.4 Microsoft.VisualBasic.Collection类 296 10.5 强类型化的集合 296 10.6 System.Collections.Generics 299 ...
C# 2.0语言的改进1067 A.1 概述1067 A.2 泛型1068 A.2.1 泛型集合1068 A.2.2 泛型方法1072 A.3 迭代器1074 A.4 匿名方法1075 A.5 运算符重载1077 A.6 全局命名空间限定符1077 A.7 部分类1078 A.8 Visual Basic XML...