System.Collections.Specialized.OrderedDictionary Dic = new System.Collections.Specialized.OrderedDictionary();
Dic.Add("a", "aaa");
Dic.Add("b", "bbb");
Dic.Keys
:
因为Dic.Keys 类型[反射后查得]为 一个私有类System.Collections.Specialized.OrderedDictionary.OrderedDictionaryKeyValueCollection
求 获得keys列表的方法
Dic.Add("a", "aaa");
Dic.Add("b", "bbb");
Dic.Keys
:
因为Dic.Keys 类型[反射后查得]为 一个私有类System.Collections.Specialized.OrderedDictionary.OrderedDictionaryKeyValueCollection
求 获得keys列表的方法
Keys是OrderedDictionary的公共属性,ICollection接口类型的
获取 ICollection 对象,该对象包含 OrderedDictionary 集合中的键。
求 获得keys列表的方法不就直接Dic.Keys就可以了吗?它是公共的属性...
OrderedDictionary myOrderedDictionary = new OrderedDictionary();
myOrderedDictionary.Add("testKey1", "testValue1");
myOrderedDictionary.Add("testKey2", "testValue2");
myOrderedDictionary.Add("keyToDelete", "valueToDelete");
myOrderedDictionary.Add("testKey3", "testValue3");ICollection keyCollection = myOrderedDictionary.Keys;
ICollection valueCollection = myOrderedDictionary.Values;// Display the contents using the key and value collections
DisplayContents(keyCollection, valueCollection, myOrderedDictionary.Count);
myOrderedDictionary.Add("testKey1", "testValue1");
myOrderedDictionary.Add("testKey2", "testValue2");
myOrderedDictionary.Add("keyToDelete", "valueToDelete");
myOrderedDictionary.Add("testKey3", "testValue3");
string[] mykeys = new string[myOrderedDictionary.Count];
string[] myvalues = new string[myOrderedDictionary.Count];
myOrderedDictionary.Keys.CopyTo(mykeys, 0);
myOrderedDictionary.Values.CopyTo(myvalues, 0);
for (int i = 0; i < myOrderedDictionary.Count; i++)
{
Console.WriteLine("Key: " + mykeys[i] + "\tValue: " + myvalues[i]);
}输出:
Key: testKey1 Value: testValue1
Key: testKey2 Value: testValue2
Key: keyToDelete Value: valueToDelete
Key: testKey3 Value: testValue3
如果用了数组的话,就用不了面向对象