2011-01-19 24 views
-1

我有一個哈希表 內GUID類型的數組我得到的值,像下面的,但我不能進去無法獲得哈希表OBJ內的陣列

IDictionaryEnumerator enumObj = moreTable.GetEnumerator(); 

       while (enumObj.MoveNext()) 
       { 
foreach (var obj in enumObj.Value) 
        { 
         _guidList.Add(new Guid(obj.ToString())); 
        } 
} 

的數組,但這並未」噸,我工作的任何一個知道如何提取存儲哈希表中的數組

回答

3

您應該使用類型安全的字典和GUID的,而不是一個泛型列表:

Dictionary<Int32, Guid> guids = new Dictionary<Int32, Guid>(); 
guids.Add(1, new Guid("{25892e17-80f6-415f-9c65-7395632f0223}")); 
guids.Add(2, new Guid("{e33898de-6302-4756-8f0c-5f6c5218e02e}")); 
guids.Add(3, new Guid("{3a768eea-cbda-4926-a82d-831cb89092aa}")); 
guids.Add(4, new Guid("{cd171f7c-560d-4a62-8d65-16b87419a58c}")); 
guids.Add(5, new Guid("{17084b40-08f5-4bcd-a739-c0d08c176bad}")); 
List<Guid> allGuids = new List<Guid>(guids.Values); 

假設你的鑰匙是一個整數,但是,這並不重要的答案。

如果你非要使用哈希表來代替:

Hashtable guids = new Hashtable(); 
//fill Hashtable like above 
ArrayList allGuids = new ArrayList(guids.Values); 
foreach (Guid guid in allGuids) { 
    //do something with the GUID...' 
} 

[所有converted從VB.Net]

1

我想你應該投enumObj.Value數組,應該允許您使用它。