社区
C#
帖子详情
如何获取集合类Dictionary中所有key的值(在线等!!!)
jinsuo_1986
2009-04-09 05:31:57
如题!
...全文
4833
8
打赏
收藏
如何获取集合类Dictionary中所有key的值(在线等!!!)
如题!
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
8 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
yobuke
2012-05-24
打赏
举报
回复
Dictionary<string, string> dic= new Dictionary<string, string>();
foreach (var item in
dic.Values
)
{
//Do sth.
}
yobuke
2012-05-24
打赏
举报
回复
Dictionary<string, string> dic= new Dictionary<string, string>();
foreach (var item in dic.Values)
{
//Do sth.
}
zisediao325
2011-03-15
打赏
举报
回复
恩 这个可以使用,只是想把它保存到数组里比较麻烦
blue601
2010-12-29
打赏
举报
回复
[Quote=引用 2 楼 zgke 的回复:]
Dictionary<string, string> _Dictionary = new Dictionary<string, string>();
foreach(string _Key in _Dictionary.Keys)
{
_Key
}
[/Quote]
这个我刚刚试过,没有问题 _Key就是你需要的键值
ljhcy99
2009-04-09
打赏
举报
回复
Dictionary <string, string> dic = new Dictionary <string, string>();
dic.keys
ojekleen
2009-04-09
打赏
举报
回复
[Quote=引用 1 楼 heyu52 的回复:]
Dictionary <string, string> dic = new Dictionary <string, string>();
dic.Values <--------值集合
[/Quote]
dic.keys<--------key集合
单个获取可以foreach
如果你的key是string 类型
foreache(string s in dic.keys)
{
console.writeline(s);
}
zgke
2009-04-09
打赏
举报
回复
Dictionary<string, string> _Dictionary = new Dictionary<string, string>();
foreach(string _Key in _Dictionary.Keys)
{
_Key
}
heyu52
2009-04-09
打赏
举报
回复
Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Values<--------值集合
C#
Dictionary
获取
某项的
key
或value
值
C#
Dictionary
获取
某项的
key
或者value
值
想要
获取
key
或者value
值
,可以循环遍历,也可以借助于C#本身的函数,如下两种方法
获取
index对应的
key
值
private string get
Dictionary
Key
ByIndex(int index) {
Dictionary
.Enumerator en =
C#
Dictionary
通过value
获取
对应的
key
值
1:最直白的循环遍历方法,可以分为遍历
key
--value键
值
对以及所有的
key
两种表现形式 2:用Linq的方式去查询(当然了这里要添加对应的命名空间 using System.Linq) 如下为
根据索引
获取
Dictionary
的
key
和value
值
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace
Dictionary
Helper { public class
Dictionary
Helper { public static K get
Key
(Di
C#
Dictionary
分别按
Key
,Value
值
升降序排序
Dictionary
<char, int> dic = new
Dictionary
<char, int>(); dic.Add('a', 1); dic.Add('b', 2); dic.Add('c', 1); dic.Add('d', 3); dic.Add('e', 8); 结果: ①dicsort1 :按
key
值
升序
Dictionary
<char, int> dicsort1 = dic.OrderBy(o => o.
Key
).ToDict.
实用代码脚本易语言源码图片组操作类
实用代码脚本易语言源码图片组操作类
C#
111,129
社区成员
642,535
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章