How to use LINQ to Objects queries

Article ID: 2278185 - View products that this article applies to.
Expand all | Collapse all

On This Page

INTRODUCTION

This article describes an All-In-One Code Framework sample that is available for download. This code sample demonstrates how to write LINQ to Objects query including some basic LINQ operations such as SELECT, UPDATE, ORDER BY, MAX and AVERAGE by using Visual C# and Visual Basic .NET. 

Difficulty level

Collapse this imageExpand this image
codefx Beginner

Download information

To download this code sample, click the following link:

    


Technical overview

The term "LINQ to Objects" refers to the use of LINQ query with any IEnumerable or IEnumerable(T) collection directly, without to use an intermediate LINQ provider or API such as LINQ to SQL or LINQ to XML. You can use LINQ to query any enumerable collections such as List (T), Array, or Dictionary(TKey, TValue). The collection may be user-defined or returned by a .NET Framework API.

In a basic sense, LINQ to Objects query represents a new approach to collections. In the old way, you had to write complex foreach loop that specified how to retrieve data from a collection. In the LINQ approach, you write declarative code that describes what you want to retrieve.

In addition, LINQ query has three main advantages compare to the traditional foreach loop:
  1. LINQ query is more concise and readable, especially when filtering multiple conditions.
  2. LINQ query provides powerful filtering, ordering, and grouping capabilities with minimum lines of application code.
  3. LINQ query can be ported to other data sources with little or no modification.
Generally, the more complex operations that you want to perform on the data, the more benefit you will notice by using LINQ query instead of traditional iteration techniques.

Note For more information about how to create the sample application and how to deploy the sample application, see the Readme.txt file that is included in the download package.

Technology category

  • LINQ

Languages

This code sample contains the following programming languages:

Collapse this tableExpand this table
LanguageProject Name
Visual C#CSLinqToObject
Visual Basic.NETVBLinqToObject

Prerequisites

  • This sample application was created by using Visual Studio 2008 with Service Pack 1 installed.

Tags

  • LINQ to Objects

MORE INFORMATION

What is All-In-One Code Framework?

All-In-One Code Framework shows most Microsoft development techniques by using code samples in different programming languages. Each example is carefully selected, composed, and documented to show one common code scenario. For more information about All-In-One Code Framework, visit the following Web site:

http://1code.codeplex.com

How to find more All-In-One Code Framework samples

To find more All-In-One Code Framework samples, you can simply click the following link:

http://support.microsoft.com/gp/gp_kbcodefx


REFERENCES

For more information about LINQ to Objects, visit the following Web sites:

LINQ to Objects

Note This is a "FAST PUBLISH" article created directly from within the Microsoft support organization. The information contained herein is provided as-is in response to emerging issues. As a result of the speed in making it available, the materials may include typographical errors and may be revised at any time without notice. See Terms of Use for other considerations.

Properties

Article ID: 2278185 - Last Review: August 12, 2010 - Revision: 3.0
APPLIES TO
  • Microsoft Visual Studio 2008 Service Pack 1
Keywords: 
kbcodefx kbinfo kbsurveynew kbnomt atdownload kbrapidpub KB2278185

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com