Đang chuẩn bị liên kết để tải về tài liệu:
Apress Introducing Dot Net 4 With Visual Studio_8

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

Tham khảo tài liệu 'apress introducing dot net 4 with visual studio_8', công nghệ thông tin, hệ điều hành 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 2.0 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 System.Linq using System.Collections.Generic 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 result.GetEnumerator for int i 0 i 25 i iter.MoveNext Console.WriteLine iter.Current 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 .