Đang chuẩn bị liên kết để tải về tài liệu:
ASP.NET 4 Unleased - p 98

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

Điều đẹp về generics ở đây là bạn không phải viết cùng một mã để chuyển đổi một đầu đọc dữ liệu vào một danh sách chung cho mỗi loại. Bạn viết GetListFromCommand () phương pháp như là một phương pháp chung một lần, và bạn có thể sử dụng phương pháp với bất kỳ loại đáp ứng các ràng buộc chung trong tương lai. | 944 CHAPTER 20 Data Access with LINQ to SQL The beautiful thing about generics here is that you don t have to write the same code to convert a data reader to a generic List for each type. You write the GetListFromCommand method as a generic method once and you can use the method with any type that meets the generic constraints in the future. The right way to think of generics is to think of a code template. You can use generics to define a certain pattern of code into which you can plug a particular type. Understanding Lambda Expressions Lambda expressions another language feature introduced with .NET Framework 3.5 provide you with an extremely terse way of defining methods. Imagine for example that you want to programmatically wire up a Click event handler to a button control. Listing 20.6 is an example of one way of doing this. LISTING 20.6 LanguageChanges NormalMethod.aspx @ Page Language C DOCTYPE html PUBLIC - W3C DTD XHTML 1.0 Transitional EN http www.w3.org TR xhtml1 DTD xhtml1-transitional.dtd script runat server void Page_Init btn.Click new EventHandler btn_Click void btn_Click object sender EventArgs e lblResult.Text DateTime.Now.ToString script html xmlns http www.w3.org 1999 xhtml head runat server title Normal Method title head body form id form1 runat server div asp Button id btn Text Go Runat server From the Library of Wow eBook New C and VB.NET Language Features 945 asp Label id lblResult Runat server div form body html In Listing 20.6 the Page_Init method associates the Button Click event with the btn_Click method. When you click the button the btn_Click method executes and displays the current date and time. Nothing special here. In .NET Framework 2.0 the notion of anonymous methods for C was introduced. The advantage of an anonymous method is that you can declare it inline. For example Listing 20.7 does the same thing as the previous page except for that it uses an anonymous method to handle the Button Click event. LISTING 20.7 LanguageChanges .

TÀI LIỆU LIÊN QUAN
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.