How can we write the Linq query for selecting a set of first authors in the books containing the word 'our' in the title, using local variables?

 Posted by Kmandapalli on 2/4/2014 | Category: LINQ Interview questions | Views: 1056 | Points: 40
Answer:

IEnumerable<Author> firstAuthors = from b in books
let title = b.Title
let authors = b.Authors
where title.Contains("our")
select authors[0];

foreach (Author author in firstAuthors)
Console.WriteLine("Author - {0}, {1}",
author.LastName, author.FirstName);


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response