Danh mục tài liệu

Chapter 8 Quick Reference

Số trang: 2      Loại file: pdf      Dung lượng: 7.26 KB      Lượt xem: 17      Lượt tải: 0    
Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Chương 8 Quick tham khảo để làm điều này Đơn giản chỉ cần làm cho bản sao. Bởi vì biến là một loại giá trị, bạn sẽ có hai bản sao của cùng một giá trị. Ví dụ: Sao chép một giá trị biến kiểu int i = 42; int copyi = i; Đơn giản chỉ cần làm cho bản sao.
Nội dung trích xuất từ tài liệu:
Chapter 8 Quick Reference Chapter 8 Quick ReferenceTo Do this Simply make the copy. Because the variable is a value type, you will have two copies of the same value. For example:Copy a value typevariable int i = 42; int copyi = i; Simply make the copy. Because the variable is a reference type, you will have two references to the same object. For example:Copy a referencetype variable Circle c = new Circle(42); Circle refc = c; Prefix the argument with the ref keyword. This makes the parameter an alias for the actual argument rather than a copy of the argument. For example:Pass an argument static void Main()to a ref parameter { int arg = 42; DoWork(ref arg); Console.WriteLine(arg); } Prefix the argument with the out keyword. This makes the parameter an alias for the actual argument rather than a copy of the argument. For example:Pass an argument static void Main()to an out parameter { int arg = 42; DoWork(out arg); Console.WriteLine(arg); } Initialize or assign a variable of type object to the value. For example:Box a value object o = 42; Cast the object reference that refers to the boxed value to the type of the value. For example:Unbox a value int i = (int)o;