Query an array of object by its property value

image_pdfimage_print
   
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Drawing;
public class Book {
    public String Title { get; set; }

    public override String ToString() {
        return Title;
    }
}

class Program {
    static void Main(string[] args) {
        Book[] books = {
      new Book { Title="A" },
      new Book { Title="F" },
      new Book { Title="E" } };

        var titles =
          books
            .Where(book => book.Title.Contains("A"))
            .Select(book => book.Title);

    }
}

    


This entry was posted in LINQ. Bookmark the permalink.