TAILIEUCHUNG - ebook Addison -Essential CSharp 4.0_3

nếu giá trị được giao là một tài sản hoặc các lĩnh vực, tên sẽ mặc định tên của trường hoặc tài sản nếu không quy định một cách rõ ràng. patent3, ví dụ, được định nghĩa bằng cách sử dụng một tên sở hữu "Tiêu đề" hơn là một bài tập với một tên ngầm. Khi đầu ra 5,8 cho thấy, các tên sở hữu kết quả được xác định bởi trình biên dịch để phù hợp với tài sản từ nơi mà giá trị được lấy. . | Static Members 247 result in compile errors. Even IntelliSense in IDEs such as Visual Studio 2008 works with the anonymous type. In Listing member names on the anonymous types are explicitly identified using the assignment of the value to the name see Title and YearOfPublication in patentl and patent2 assignments . However if the value assigned is a property or field the name will default to the name of the field or property if not specified explicitly. patents for example is defined using a property name Title rather than an assignment to an implicit name. As Output shows the resultant property name is determined by the compiler to match the property from where the value was retrieved. Although the compiler allows anonymous type declarations such as the ones shown in Listing you should generally avoid anonymous type declarations and even the associated implicit typing with var until you are working with lambda and query expressions that associate data from different types or you are horizontally projecting the data so that for a particular type there is less data overall. Until frequent querying of data out of collections makes explicit type declaration burdensome it is preferable to explicitly declare types as outlined in this chapter. Static Members The HelloWorld example in Chapter 1 first presented the keyword static however it did not define it fully. This section defines the static keyword fully. To begin consider an example. Assume that the employee Id value needs to be unique for each employee. One way to accomplish this is to store a counter to track each employee ID. If the value is stored as an instance field however every time you instantiate an object a new NextId field will be created such that every instance of the Employee object would consume memory for that field. The biggest problem is that each time an Employee object instantiated the NextId value on all of the previously instantiated Employee objects would need to be updated with

TỪ KHÓA 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.