Type perfect Object

Boxing As you have just seen, variables of type object can refer to any object of any reference type. That is, they can refer to any instance of a class. However, variables of type object can also refer to a value type. | Boxing As you have just seen variables of type object can refer to any object of any reference type. That is they can refer to any instance of a class. However variables of type object can also refer to a value type. For example the following two statements initialize the variable i of type int a value type to 42 and then initialize the variable o of type object a reference type to i int i 42 object o i The effect of the second statement is subtle. Remember that i is a value type and it exists in the stack. If the reference inside o referred directly to i the reference would be referring to the stack. However all references refer to objects on the heap. Instead a piece of memory is allocated from the heap an exact copy of the value inside i is stored in this piece of memory and the reference inside o is pointed to the copy. Creating references to items on the stack could seriously compromise the robustness of the runtime and create a potential security flaw so it is not allowed. This automatic copying of an item from the stack to the heap is called boxing. The following graphic shows the result IMPORTANT If you modify the original value of a variable you are not modifying the value that now exists on the heap because it s just a copy. Calling Methods Methods exist to be called You call a method by name to ask it to perform its task. If the method requires information as specified by its parameters you must supply the information requested. If the method returns information as specified by its return type you should arrange to capture this information somehow. Specifying the Method Call Syntax The syntax of a C method call is as follows methodName argumentList The methodName must exactly match the name of the method you re calling. Remember C is a case-sensitive language. The argumentList supplies the optional information that the method accepts. You must supply an argument for each parameter and the value of each argument must be compatible with the type of its .

Bấm vào đây để xem trước nội dung
TÀI LIỆU LIÊN QUAN
5    176    1
5    255    1
5    106    0
5    121    1
6    103    1
6    107    1
6    121    1
6    103    0
6    140    0
TÀI LIỆU MỚI ĐĂNG
308    6    1    09-06-2024
94    62    2    09-06-2024
Đã 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.