DictionaryEntry不适用于Dictionary? [英] DictionaryEntry does not work with Dictionary?
问题描述
从MS docs复制代码。将HashTable更改为Dictionary,它将无法编译。它应该被命名为HashTableEntry而不是DictionaryEntry,因为它似乎不适用于Dictionary吗?我知道我可以使用KeyValuePair。我只想调查
a新发现。
Private Sub myhash()
'Dim openWith As New Hashtable()
Dim openWith As New Dictionary(Of String,String)
openWith.Add(" txt"," notepad.exe")
openWith.Add(" bmp"," paint。 exe")
openWith.Add(" dib"," paint.exe")
openWith.Add(" rtf"," wordpad.exe")
For Each de作为DictionaryEntry在openWith
Debug.Print(" Key = {0},Value = {1}",
de.Key,de.Value)
Next de
结束子
Mary
嗨玛丽,
底部的链接是两种方式之间的一个很好的解释。
试试这个
< pre class ="prettypri nt lang-vb"style =""> Private Sub myhash()
'Dim openWith As New Hashtable()
Dim openWith As New Dictionary(Of String,String)
openWith.Add( " txt"," notepad.exe")
openWith.Add(" bmp"," paint.exe")
openWith.Add(" dib"," paint.exe" ;)
openWith.Add(" rtf"," wordpad.exe")
For Each de As KeyValuePair(Of String,string)in openWith
Debug.Print(" Key = {0},值= {1}",
de.Key,de.Value)
下一个de
结束子
参见  ; https://stackoverflow.com/questions/905424/keyvaluepair-vs-dictionaryentry
Copied the code from MS docs. Changed HashTable to Dictionary and it will not compile. Should this have been named HashTableEntry and not DictionaryEntry since it doesn't seem to work with a Dictionary? I know I can use KeyValuePair. I just wanted to investigate a new discovery.
Private Sub myhash() ' Dim openWith As New Hashtable() Dim openWith As New Dictionary(Of String, String) openWith.Add("txt", "notepad.exe") openWith.Add("bmp", "paint.exe") openWith.Add("dib", "paint.exe") openWith.Add("rtf", "wordpad.exe") For Each de As DictionaryEntry In openWith Debug.Print("Key = {0}, Value = {1}", de.Key, de.Value) Next de End Sub
Mary
Hi Mary,
The link at the bottom is a good explanation between the two ways.
Try this
Private Sub myhash() ' Dim openWith As New Hashtable() Dim openWith As New Dictionary(Of String, String) openWith.Add("txt", "notepad.exe") openWith.Add("bmp", "paint.exe") openWith.Add("dib", "paint.exe") openWith.Add("rtf", "wordpad.exe") For Each de As KeyValuePair(Of String,string) In openWith Debug.Print("Key = {0}, Value = {1}", de.Key, de.Value) Next de End SubSee also https://stackoverflow.com/questions/905424/keyvaluepair-vs-dictionaryentry
这篇关于DictionaryEntry不适用于Dictionary?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!