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>(????));
You should pass lambda into that .Select
method, not just expression:
.Select(movie => new KeyValuePair<int,bool>(movie.Id, movie.IsReleased))
hope that helps!
//.Select(new KeyValuePair<int,bool>(????));
.Select(movie => new KeyValuePair<int,bool>()
{ Key = movie.Id, Value = movie.IsReleased} );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With