TAILIEUCHUNG - Apress pro LINQ Language Integrated Query in C# 2008 phần 2

Những ngôn ngữ cho phép sử dụng LINQ có thể cung cấp đầy đủ type-safery và compile-time cho việc kiểm tra các biểu thức truy vấnNhững ngôn ngữ cho phép sử dụng LINQ có thể cung cấp đầy đủ type-safery và compile-time cho việc kiểm tra các biểu thức truy vấn, và những công cụ phát triển có thể cung cấp đầy đủ việc hỗ trợ intellisense, debugging, and rich refactoring khi đang viết mã LINQ. | CHAPTER 2 C LANGUAGE ENHANCEMENTS FOR LINQ 33 This could even be rewritten as the following Enumerable enumerable one two three Enumerable finalEnumerable enumerable .Where lXl .Where lX2 .Where lX3 Wow that s much easier to read. You can now read the statement from left to right top to bottom. As you can see this syntax is very easy to follow once you understand what it is doing. Because of this you will often see LIN Q queries written in this format in much of the LINQ documentation and in this book. Ultimately what you need is the ability to have a static method that you can call on a class instance. This is exactly what extension methods are and what they allow. They were added to C to provide a syntactically elegant way to call a static method without having to pass the method s first argument. This allows the extension method to be called as though it were a method of the first argument which makes chaining extension method calls far more readable than if the first argument was passed. Extension methods assist LIN Q by allowing the Standard Query Operators to be called on the IEnumerable T interface. Note Extension methods are methods that while static can be called on an instance object of a class rather than on the class itself. Extension Method Declarations and Invocations Specifying a method s first argument with the this keyword modifier will make that method an extension method. The extension method will appear as an instance method of any object with the same type as the extension method s first argument s data type. For example if the extension method s first argument is of type string the extension method will appear as a string instance method and can be called on any string object. Also keep in mind that extension methods can only be declared in static classes. Here is an example of an extension method namespace public static class StringConversions public static double ToDouble this string s return s public .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.