TAILIEUCHUNG - Apress - Accelerated C#_8

Tham khảo tài liệu 'apress - accelerated c#_8', công nghệ thông tin, cơ sở dữ liệu phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | CHAPTER 14 EXTENSION METHODS changed. C on the other hand offers a hybrid environment in which you are free to implement functional programming if you choose. Also those familiar with the Standard Template Library STL will get a familiar feeling from this style of programming. STL swept through the C programming community back in the early 1990s and encouraged a more functional programming thought process. Operation Chaining Using extension methods operation chaining becomes a more natural process. Again it s nothing that you could not have done in the C days using plain static methods and anonymous methods. However with the streamlined syntax chaining actually removes the clutter and can trigger some innovative thinking. Let s start with the example from the previous section in which we took a list of integers and transformed them into a list of doubles. This time we ll look at how we can actually chain operations in a fluid way. Let s suppose that after dividing the integers by 3 we want to then compute the square of the result. The following code shows how to do that using System using using public static class MyExtensions public static IEnumerable R Transform T R this IEnumerable T input Func T R op foreach var item in input yield return op item public class TransformExample static IEnumerable int CreateInfiniteList int n 0 while true yield return n static double DivideByThree int n return double n 3 static double Square double r return r r static void Main var divideByThree new Func int double DivideByThree var squareNumber 502 CHAPTER 14 EXENTENSION METHODS new Func double double Square var result CreateInfiniteList . Transform divideByThree . Transform squareNumber var iter for int i 0 i 25 i Isn t that cool In one statement of code I took an infinite list of integers and applied a divisor followed by a squaring operation and the end result is a .

TỪ KHÓA LIÊN QUAN
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.