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();
精彩评论