简体   繁体   中英

Finding all values in a Dictionary<string, object> where value contains substring

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM