I have a dictionary
Dictionary<string, object> ItemSource;
I want to select items that value contains a string.
Here's the code that I'm using
var ItemSource=_db.Users.ToDictionary(m=>m.FullName,M=>M.UserName as object);
var source=ItemSource.Where(a => a.Value.ToString().Contains(pattern))
But this return all items.
Items in ItemsSorce is
{[11,رحیمی]}
{12,سالاری}
{13,محمدی}
You can try this:-
ItemSource.Where(a=> a.Key.Contains(pattern)).Select(a=> a.Value);
EDIT:
var source = ItemSource.Where(a=> a.Value == pattern).Select(a=> a.Key);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.