开发者

LINQ-to-objects, get value from dictionary

开发者 https://www.devze.com 2023-02-21 04:18 出处:网络
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.

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

精彩评论

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