开发者

Can't get the array inside hashtable obj

开发者 https://www.devze.com 2023-02-05 05:54 出处:网络
I have an array of type Guid inside an HashTable I get the values like the following but I can\'t get the array inside

I have an array of type Guid inside an HashTable I get the values like the following but I can't get the array inside

    IDictionaryEnumerator enumObj = moreTab开发者_如何学编程le.GetEnumerator();

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

but this doesn't working with me any one know how to extract an array stored inside Hash table


You should use a type safe Dictionary and a generic List of Guid's instead:

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);

Assuming that your key is an integer, but that doesn't matter for the answer.

If you insist upon using a HashTable instead:

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

[ all converted from VB.Net ]


I guess you should cast enumObj.Value to array, that should allow you to use it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号