LINQ Example - Basic idea on how to query using LINQ

Karthikanbarasan
Posted by Karthikanbarasan under LINQ category on | Points: 40 | Views : 2630
This code sample shows how to query usign LINQ

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Demo
{
class Program
{
static void Main(string[] args)
{
string[] namesList = { "AB", "AC", "BB", "BC", "CA", "CB", "DD", "DA", "ABC", "GD", "ED", "AA", "BD" };

var queryResult =
from n in namesList
where n.StartsWith("A")
select n;

Console.WriteLine("Names beginning with A:");

foreach (var item in queryResult)
{
Console.WriteLine(item);
}

Console.Write("press Enter to continue:");
Console.ReadLine();
}

}
}

Comments or Responses

Login to post response