LINQ Example - Basic idea on how to query using 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();
        }

    }
}
Ebook Download
View all
Learn
View all