开发者

LINQ-to-objects, get value from dictionary

I have an on object, called user, that has a property of type dictionary called AttributeBag.

I want to pull out the Key in the AttributeBag of "PasswordQuestion" and get its value.

The below is not correct...

var x = user.Find(a =&开发者_JS百科gt; a.AttributeBag.Key["PasswordQuestion"]).value;

help


var x = user.Find(a => a.AttributeBag.Key["PasswordQuestion"]).value;

becomes

var x = user.AttributeBag.Select(s => s.Key == "PasswordQuestion")
        .First().ToString();

or

var x = (from a in _user.AttributeBag
         where a.Key == "PasswordQuestion"
         select a.Value).First().ToString();

5000 ways to skin a cat


var x = user.AttributeBag.Where(a => a.Key == "PasswordQuestion") .First().Value.ToString();

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜