Dictionary

从字典(DicRoleForScope)中查询对应(role)的值再赋值给其他变量( DicSelectedRoleForScope)

Dictionary<string, object> dic = DicRoleForScope.Where(s => s.Value.ToString().Contains(role)).
Select(q => new { q.Key, q.Value }).
ToList().AsEnumerable().ToDictionary(d => d.Key, d => (object)d.Value); // where对比中使用Contains

KeyValuePair<string, object> kvp = dic.FirstOrDefault();

if (kvp.Key != null && kvp.Value != null) //注意判断为空否
{
DicSelectedRoleForScope.Add(kvp.Key, kvp.Value); //Dictionary只能以键值对的形式添加
}

posted @ 2019-08-31 15:10  马玲  阅读(242)  评论(0编辑  收藏  举报