KeyValuePair in Lambda expression

c#, keyvaluepair, lambda

Solution

You should pass lambda into that `.Select` method, not just expression:

.Select(movie => new KeyValuePair<int,bool>(movie.Id, movie.IsReleased))

hope that helps!

Problem

I am trying to create a KeyValue pair collection with lambda expression. Here is my class and below that my lambda code. I failed to create the KeyValuePair. I want to get a collection of KeyValuePair of Id, IsReleased for the comedy movies. I put those KeyValuePair in HashSet for quick search. ``` public class Movie{ public string Name{get;set;} public int Id{get;set;} public bool IsReleased{get;set;} //etc } List<Movie> movieCollection=//getting from BL var movieIdReleased= new HashSet<KeyValuePair<int,bool>>(movieCollection.Where(mov=> mov.Type== "comedy") .Select(new KeyValuePair<int,bool>(????)); ```

Original source