How to search for a part of a dictionary key?

本小妞迷上赌 提交于 2019-12-05 16:00:23

You can check if there's any entry which a key containing "Bolognese" using Any()

If Not PriceList.Where(Function(x) x.Key.Contains("Bolognese")).Any()
    Console.WriteLine("No Bolognese, sorry")
End If

To get a subset of the dictionary with keys containing "Bolognese" only:

Dim subsetOfDictionary = PriceList _ 
        .Where(Function(x) x.Key.Contains("Bolognese")) _ 
        .ToDictionary(Function(x) x.Key, Function(x) x.Value)

To get the list of prices for all entries containing "Bolognese":

Dim pricesForAllThingsBolognese = PriceList _
        .Where(Function(x) x.Key.Contains("Bolognese")) _
        .Select(Function(x) x.Value) _
        .ToList()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!