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;
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;
Tài liệu có liên quan:
-
Giáo trình Lập trình hướng đối tượng: Phần 2
154 trang 316 0 0 -
Kỹ thuật lập trình trên Visual Basic 2005
148 trang 310 0 0 -
Bài thuyết trình Ngôn ngữ lập trình: Hệ điều hành Window Mobile
30 trang 293 0 0 -
NGÂN HÀNG CÂU HỎI TRẮC NGHIỆM THIẾT KẾ WEB
8 trang 249 0 0 -
Bài giảng Một số hướng nghiên cứu và ứng dụng - Lê Thanh Hương
13 trang 248 0 0 -
Giáo trình Lập trình cơ bản với C++: Phần 1
77 trang 242 0 0 -
Giáo án Tin học lớp 11 (Trọn bộ cả năm)
125 trang 231 1 0 -
Bài tập lập trình Windows dùng C# - Bài thực hành
13 trang 204 0 0 -
Thiết kế mạch logic bằng Verilog - HDL
45 trang 197 0 0 -
Bài giảng Nhập môn về lập trình - Chương 1: Giới thiệu về máy tính và lập trình
30 trang 189 0 0