LINQ to Objects

LINQ is the new way of querying data from various sources. Langugae integrated query supports

  • ·         LINQ to Objects
  • ·         LINQ to DataSets
  • ·         LINQ to SQL
  • ·         LINQ to Entities
  • ·         LINQ to XML

 LINQ to Objects

LINQ to object supports the native query language in .Net with intellisense. Query Operators like select, where, join, etc. can be used against any .NET collection. LINQ integrate the use of Lambda expressions. It also uses the deferred query execution feature, where the query will be executed at the time of referring the result.

 LINQ to Object example

namespace ConsoleApplication{    class Program
    {
        static void Main(string[] args)
        {
          string[] names = { "John", "George", "Anitha", "Hari", "Vishnu", "Gauri" };
            Func<string, bool> filter = s => s.Length == 5;
            Func<string, string> extract = s => s;
            Func<string, string> project = s => s.ToUpper();

            IEnumerable<string> expr = names
                    .Where(filter)
                    .OrderBy(extract)
                    .Select(project);

            foreach (string item in expr)
                Console.WriteLine(item);

            Console.Read();
        }       
    }
}

 Result:

GAURI

Advertisements

About ambilykk

I am a Technology Evangelist on Microsoft Technologies. I am carrying the passion on Microsoft technologies specifically on web technologies such as ASP .Net and Ajax. My interests also include Azure and Visual Studio. Technology adoption and learning is my key strength and technology sharing is my passion.
This entry was posted in LINQ and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s