| In this tutorial we will look at LINQ Projection, which is | | | | { |
| when we can select specific data from a source | | | | _name = value; |
| without retrieving all fields. We will be creating a class | | | | } |
| to define a list in which we will create a number of | | | | }public string City |
| people with IDs, names and cities. Then we will use | | | | {get |
| buttons to select only parts of this data. | | | | {return _city; |
| First, we will start off by creating a new Windows | | | | }set |
| Form application in VS.NET 2008. Next, we will create | | | | { |
| a class - call it aList - and define our list object:using | | | | _city = value; |
| System;using System.Collections.Generic;using | | | | } |
| System.Linq;using System.Text;namespace | | | | } |
| LINQProjection_cs | | | | } |
| {class aList | | | | } |
| {private int _personID;private string _name;private | | | | This class defines a Property for each field we want, |
| string _city;public int PersonID | | | | and its data type. |
| {get | | | | Next, we can add our Controls to the Form. We will |
| {return _personID; | | | | add three buttons, and a Rich TextBox. The buttons |
| }set | | | | will retrieve all of the IDs, Names and Cities, individually. |
| { | | | | This will demonstrates how we can retrieve the |
| _personID = value; | | | | specific data that we want. Once we have our |
| } | | | | controls, we can move onto the code-behind of the |
| }public string Name | | | | form and define our data. We will add a few sample |
| {get | | | | entries: |
| {return _name; | | | | Please vist to complete this article. Happy coding! |
| }set | | | | |