microsoft visual c 2008 step by step phần 7

Nếu có bất kỳ sự khác biệt giữa định nghĩa giao diện và thực hiện tuyên bố, các lớp học sẽ không biên hiện một giao diện rõ ràng có thể dường như là một tiết nhỏ, nhưng nó cung cấp một số lợi thế mà giúp bạn viết rõ ràng hơn, duy trì nhiều hơn, và mã số dự đoán nhiều hơn. | 376 Part III Creating Components this case customer parameter and yields a collection of TResult in this case string objects. The value returned by the Select method is an enumerable collection of TResult again string objects. Note If you need to review how extension methods work and the role of the first parameter to an extension method go back and revisit Chapter 12 Working with Inheritance. The important point to understand from the preceding paragraph is that the Select method returns an enumerable collection based on a single type. If you want the enumerator to return multiple items of data such as the first and last name of each customer you have at least two options You can concatenate the first and last names together into a single string in the Select method like this IEnumerable string customerFullName cust You can define a new type that wraps the first and last names and use the Select method to construct instances of this type like this class Names public string FirstName get set public string LastName get set IEnumerable Names customerName cust new Names FirstName LastName The second option is arguably preferable but if this is the only use that your application makes of the Names type you might prefer to use an anonymous type instead of defining a new type specifically for a single operation like this var customerName cust new FirstName LastName Notice the use of the var keyword here to define the type of the enumerable collection. The type of objects in the collection is anonymous so you cannot specify a specific type for the objects in the collection. Chapter 20 Querying In-Memory Data by Using Query Expressions 377 Filtering Data The Select method enables you to specify or project the fields that you want to include in the enumerable collection. However you might also want to restrict the rows that the enumerable

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã 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.