Sao chép các biến int và lớp học Tất cả các loại nguyên thủy như int được gọi là kiểu giá trị. Khi bạn khai báo một biến int, trình biên dịch tạo ra mã mà giao một khối bộ nhớ đủ lớn để giữ một số nguyên. Một tuyên bố mà chỉ định một giá trị (như 42) để int nguyên nhân giá trị để được sao chép vào bộ nhớ khối này | Copying int Variables and Classes All primitive types such as int are called value types. When you declare an int variable the compiler generates code that allocates a block of memory big enough to hold an integer. A statement that assigns a value such as 42 to the int causes the value to be copied to this block of memory. Class types such as Circle described in Chapter 7 are handled differently. When you declare a Circle variable the compiler does not generate code that allocates a block of memory big enough to hold a Circle all it does is allot a small piece of memory that can potentially hold the address of or a reference to another block of memory containing a Circle. The memory for the Circle object itself is only allocated when the new keyword is used to create the object. This demonstrates that value types are so called because they hold values directly. Reference types such as classes hold references to blocks of memory. NOTE If you are a C or C programmer you might be tempted to think of reference types simply as pointers. While reference types in C exhibit many similarities to pointers they provide far more functionality. For example in a C or C application it is possible to make a pointer reference almost any block of memory regardless of the type of data the block is holding. Sometimes this is useful but more often than not it is the cause of many insidious programming errors. In C all references are strongly typed you cannot declare a reference variable that refers to one type such as Circle and then use the variable to access a block of memory holding a different type. There are other differences as well concerning the way in which the common language runtime manages and reclaims memory. These features are discussed in Chapter 13 Using Garbage Collection and Resource Management. Because of the different ways that they hold data value types are sometimes called direct types and reference types are sometimes called indirect types. You need to fully .