using System.Collections.Generic;
public static void Main()
Console.WriteLine("-------------------------------------------------------------------------------------------------------------------------");
Console.WriteLine("| Querying a Data Table Using Select Method and Lambda Expressions in C# |");
Console.WriteLine("| URL base: http://www.c-sharpcorner.com/UploadFile/0f68f2/querying-a-data-table-using-select-method-and-lambda-express/|");
Console.WriteLine("-------------------------------------------------------------------------------------------------------------------------");
DataTable dt = new DataTable();
dt.Columns.Add("CEP", typeof(string));
dt.Columns.Add("ABREVIACAO", typeof(string));
dt.Columns.Add("RUA", typeof(string));
dt.Columns.Add("NUMERO", typeof(int));
DataColumn[] keys = new DataColumn[1];
dt.Rows.Add("203456876", "John", "12 Main Street, Newyork, NY", 15);
dt.Rows.Add("203456877", "SAM", "13 Main Ct, Newyork, NY", 25);
dt.Rows.Add("203456878", "Elan", "14 Main Street, Newyork, NY", 35);
dt.Rows.Add("203456879", "Smith", "12 Main Street, Newyork, NY", 45);
dt.Rows.Add("203456880", "SAM", "345 Main Ave, Dayton, OH", 55);
dt.Rows.Add("203456881", "Sue", "32 Cranbrook Rd, Newyork, NY", 65);
dt.Rows.Add("203456882", "Winston", "1208 Alex St, Newyork, NY", 65);
dt.Rows.Add("203456883", "Mac", "126 Province Ave, Baltimore, NY", 85);
dt.Rows.Add("203456884", "SAM", "126 Province Ave, Baltimore, NY", 95);
Console.WriteLine(" Retrieving all the ABREVIACAO except having name 'SAM'\n");
foreach (DataRow o in dt.Select("ABREVIACAO <> 'SAM'"))
Console.WriteLine("\t" + o["CEP"] + "\t" + o["ABREVIACAO"] + "\t" + o["RUA"] + "\t" + o["NUMERO"]);
Console.WriteLine("\n Checking whether any person is teen-ager or not...");
if(dt.Select("NUMERO >= 13 AND NUMERO <= 19").Any())
Console.WriteLine("\t Yes, we have some teen-agers in the list");