user275642
user275642

Reputation:

How to create a lambda expression for a nested generic in C#?

I have a data structure defined as:
Dictionary<Guid, List<string>> _map = new Dictionary<Guid, List<string>>();

I'm trying to create a lambda expression that given a string, returns a IEnumerable of Guids associated with any List<string> containing that string.

Is this reasonable/possible or should I use a more appropriate data structure?

Thanks in advance!
Kim

Upvotes: 0

Views: 788

Answers (1)

JaredPar
JaredPar

Reputation: 754863

Try the following

Func<string,IEnumerable<Guid>> lambda = filter => (
   _map
      .Where(x => x.Value.Contains(filter))
      .Select(x => x.Key));

Usage

var keys1 = filter("foo");
var keys2 = filter("bar");

Upvotes: 3

Related Questions