怎么循环得到Dictionary的key值?

xinrensheng 2012-07-21 03:27:11
Dim dic As New Dictionary(Of String, String)
dic.Add("111", "")
dic.Add("32", "")

我现在要把这两个key值放到textbox1中去,key之间用vbcrlf分开 要怎么写呢?(是要key值不是item的值.)

我这样写它报错:No default member found for type 'KeyCollection'.
一定要先另外弄个数组k才能把key取出来吗?这么麻烦?

Dim k
k = dic3.Keys
For i = 0 To dic3.Count - 1

TextBox1.Text = TextBox1.Text + k(i)+vbcrlf

Next




谢谢!!
...全文
362 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
xinrensheng 2012-07-21
  • 打赏
  • 举报
回复
错误 4 类型“String”的值无法转换为“System.Net.Mail.Attachment”。
要怎么办呢?求大侠们帮看下.
多谢!!
xinrensheng 2012-07-21
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

VB code

Dim dic As New Dictionary(Of String, String)
dic.Add("111", "")
dic.Add("32", "")
For Each k In dic.Keys
...
Next
[/Quote]
这里这个k不用先dim下什么就可以用呵?不会有什么意外的?
另外我这个k是文件路径,我想作为邮件附件的,我这样:
For Each k In dic.Keys
MailMessage.Attachments.Add(k)
Next

它报错,提示说:类型string的值无法转换为system.net.mail.attchment .要怎么办呢? 意思是说字符串无法转换为附件? 可是我直接用字符串比如MailMessage.Attachments.Add("c:\111.txt")是可以的.
xinrensheng 2012-07-21
  • 打赏
  • 举报
回复
Thanks!测试下先
人生无悔 2012-07-21
  • 打赏
  • 举报
回复

Dim dic As New Dictionary(Of String, String)
dic.Add("111", "")
dic.Add("32", "")
For Each k In dic.Keys
...
Next

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧