Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

KeyValuePair in Lambda expression

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>(????));
like image 305
Murali Murugesan Avatar asked Jan 24 '13 14:01

Murali Murugesan


2 Answers

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

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

hope that helps!

like image 113
roman-roman Avatar answered Oct 24 '22 19:10

roman-roman


 //.Select(new KeyValuePair<int,bool>(????));
 .Select(movie => new KeyValuePair<int,bool>() 
              { Key = movie.Id, Value = movie.IsReleased} );
like image 2
Henk Holterman Avatar answered Oct 24 '22 19:10

Henk Holterman