0

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

1
  • Are you using the dictionary backwards? I mean you want the key given the values? Commented Feb 17, 2010 at 22:32

1 Answer 1

3

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");
Sign up to request clarification or add additional context in comments.

1 Comment

That's it! Just a small change in usage to: var keys1 = lambda("foo") Saved me a ton of time - thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.