This chapter will introduce LINQ and show how it fits into C# and into dịch - This chapter will introduce LINQ and show how it fits into C# and into Việt làm thế nào để nói

This chapter will introduce LINQ an

This chapter will introduce LINQ and show how it fits into C# and into your programming. Subsequent chapters will dive into the details of using LINQ to retrieve and manipulate data in databases and in other data repositories. You’ll learn about ADO.NET in Chapter 16.
Defining and Executing a Query In previous versions of C#, if you wanted to find an object in a database you had to leave C# and turn to the Framework (most often ADO.NET). With LINQ, you can stay within C#, and thus within a fully class-based perspective.
Many books start with anonymous methods, then introduce Lambda expressions, and finally introduce LINQ. It is my experience that it is far easier to understand each of these concepts by going in the opposite direction, starting with queries and introducing Lambda expressions for what they are: enabling technologies. Each of these topics will, however, be covered here and in subsequent chapters.
Let’s start simply by searching a collection for objects that match a given criterion, as demonstrated in Example 13-1.
Example 13-1. A simple LINQ query
using System;
using System.Collections.Generic;
using System.Linq;
namespace Programming_CSharp
{
// Simple customer class
public class Customer


{
public string FirstName { get; set; }
public string LastName { get; set; }
public string EmailAddress { get; set; }
// Overrides the Object.ToString() to provide a
// string representation of the object properties.
public override string ToString()
{
return string.Format("{0} {1}
Email: {2}", FirstName, LastName, EmailAddress);
}
}
// Main program
public class Tester
{
static void Main()
{
List customers = CreateCustomerList();

Example 13-1. A simple LINQ query (continued)
// Find customer by first name
IEnumerable result =
from customer in customers
where customer.FirstName == "Donna"
select customer;
Console.WriteLine("FirstName == "Donna"");
foreach (Customer customer in result) Console.WriteLine(customer.ToString());
customers[3].FirstName = "Donna";
Console.WriteLine("FirstName == "Donna" (take two)");
foreach (Customer customer in result) Console.WriteLine(customer.ToString());
}
// Create a customer list with sample data
private static List CreateCustomerList()
{
List customers = new List
{
new Customer
{
FirstName = "Orlando",
LastName = "Gee",
0/5000
Từ: -
Sang: -
Kết quả (Việt) 1: [Sao chép]
Sao chép!
This chapter will introduce LINQ and show how it fits into C# and into your programming. Subsequent chapters will dive into the details of using LINQ to retrieve and manipulate data in databases and in other data repositories. You’ll learn about ADO.NET in Chapter 16.Defining and Executing a Query In previous versions of C#, if you wanted to find an object in a database you had to leave C# and turn to the Framework (most often ADO.NET). With LINQ, you can stay within C#, and thus within a fully class-based perspective. Many books start with anonymous methods, then introduce Lambda expressions, and finally introduce LINQ. It is my experience that it is far easier to understand each of these concepts by going in the opposite direction, starting with queries and introducing Lambda expressions for what they are: enabling technologies. Each of these topics will, however, be covered here and in subsequent chapters.Let’s start simply by searching a collection for objects that match a given criterion, as demonstrated in Example 13-1.Example 13-1. A simple LINQ queryusing System; using System.Collections.Generic;using System.Linq; namespace Programming_CSharp { // Simple customer class public class Customer { public string FirstName { get; set; } public string LastName { get; set; } public string EmailAddress { get; set; } // Overrides the Object.ToString() to provide a // string representation of the object properties. public override string ToString() { return string.Format("{0} {1}
Email: {2}", FirstName, LastName, EmailAddress); } } // Main program public class Tester { static void Main() { List customers = CreateCustomerList();  Example 13-1. A simple LINQ query (continued) // Find customer by first name IEnumerable result = from customer in customers where customer.FirstName == "Donna" select customer; Console.WriteLine("FirstName == "Donna""); foreach (Customer customer in result) Console.WriteLine(customer.ToString()); customers[3].FirstName = "Donna"; Console.WriteLine("FirstName == "Donna" (take two)"); foreach (Customer customer in result) Console.WriteLine(customer.ToString()); } // Create a customer list with sample data private static List CreateCustomerList() { List customers = new List { new Customer { FirstName = "Orlando", LastName = "Gee",
đang được dịch, vui lòng đợi..
Kết quả (Việt) 2:[Sao chép]
Sao chép!
Chương này sẽ giới thiệu LINQ và hiển thị nó như thế nào phù hợp với C # và thành lập trình của bạn. Chương tiếp theo sẽ đi sâu vào các chi tiết của việc sử dụng LINQ để truy xuất và thao tác dữ liệu trong cơ sở dữ liệu và kho dữ liệu khác. Bạn sẽ tìm hiểu về ADO.NET trong Chương 16.
De fi hoạch và Thực hiện một truy vấn Trong các phiên bản trước đó của C #, nếu bạn muốn tìm một đối tượng trong một cơ sở dữ liệu bạn phải rời C # và chuyển sang các Framework (thường xuyên nhất ADO.NET) . Với LINQ, bạn có thể ở trong C #, và do đó trong một góc nhìn hoàn toàn dựa trên lớp.
Nhiều cuốn sách bắt đầu với phương pháp vô danh, sau đó giới thiệu biểu thức Lambda, và cuối cùng giới thiệu LINQ. Đó là kinh nghiệm của tôi rằng đó là dễ dàng hơn để hiểu nhau của các khái niệm này bằng cách đi theo hướng ngược lại, bắt đầu với các truy vấn và giới thiệu biểu thức Lambda cho những gì họ đang: công nghệ cho phép. Mỗi một chủ đề sẽ, tuy nhiên, được phủ ở đây và trong các chương sau.
Hãy bắt đầu bằng cách tìm kiếm một bộ sưu tập cho các đối tượng phù hợp với một tiêu chí nhất định, như đã chứng minh trong Ví dụ 13-1.
Ví dụ 13-1. Một truy vấn đơn giản LINQ
using System;
using System;
sử dụng System.Linq;
namespace Programming_CSharp
{
// Simple lớp khách hàng
public class Customer


{
public string FirstName {get; bộ; }
Công chuỗi LastName {get; bộ; }
Public string EmailAddress {get; bộ; }
// Ghi đè Object.ToString () để cung cấp một
. Chuỗi đại diện // các thuộc tính đối tượng
public override string ToString ()
{
return string.Format ( "{0} {1} nEmail: {2}", FirstName , LastName, EmailAddress);
}
}
// Main chương trình
public class Tester
{
static void Main ()
{
Danh sách customers = CreateCustomerList();

Example 13-1. A simple LINQ query (continued)
// Find customer by first name
IEnumerable result =
from customer in customers
where customer.FirstName == "Donna"
select customer;
Console.WriteLine("FirstName == "Donna"");
foreach (Customer customer in result) Console.WriteLine(customer.ToString());
customers[3].FirstName = "Donna";
Console.WriteLine("FirstName == "Donna" (take two)");
foreach (Customer customer in result) Console.WriteLine(customer.ToString());
}
// Create a customer list with sample data
private static List CreateCustomerList()
{
List customers = new List
{
new Customer
{
FirstName = "Orlando",
LastName = "Gee",
đang được dịch, vui lòng đợi..
 
Các ngôn ngữ khác
Hỗ trợ công cụ dịch thuật: Albania, Amharic, Anh, Armenia, Azerbaijan, Ba Lan, Ba Tư, Bantu, Basque, Belarus, Bengal, Bosnia, Bulgaria, Bồ Đào Nha, Catalan, Cebuano, Chichewa, Corsi, Creole (Haiti), Croatia, Do Thái, Estonia, Filipino, Frisia, Gael Scotland, Galicia, George, Gujarat, Hausa, Hawaii, Hindi, Hmong, Hungary, Hy Lạp, Hà Lan, Hà Lan (Nam Phi), Hàn, Iceland, Igbo, Ireland, Java, Kannada, Kazakh, Khmer, Kinyarwanda, Klingon, Kurd, Kyrgyz, Latinh, Latvia, Litva, Luxembourg, Lào, Macedonia, Malagasy, Malayalam, Malta, Maori, Marathi, Myanmar, Mã Lai, Mông Cổ, Na Uy, Nepal, Nga, Nhật, Odia (Oriya), Pashto, Pháp, Phát hiện ngôn ngữ, Phần Lan, Punjab, Quốc tế ngữ, Rumani, Samoa, Serbia, Sesotho, Shona, Sindhi, Sinhala, Slovak, Slovenia, Somali, Sunda, Swahili, Séc, Tajik, Tamil, Tatar, Telugu, Thái, Thổ Nhĩ Kỳ, Thụy Điển, Tiếng Indonesia, Tiếng Ý, Trung, Trung (Phồn thể), Turkmen, Tây Ban Nha, Ukraina, Urdu, Uyghur, Uzbek, Việt, Xứ Wales, Yiddish, Yoruba, Zulu, Đan Mạch, Đức, Ả Rập, dịch ngôn ngữ.

Copyright ©2025 I Love Translation. All reserved.

E-mail: