TAILIEUCHUNG - Visual studio 2010 part 10

Coding Fields và Properties lĩnh vực A là một biến mà là một thành viên của một lớp (loại), trái với các biến được khai báo bên trong các phương pháp, gọi là các biến cục bộ địa phương hoặc các biến scoped. Tài sản là thành viên kiểu đó cung cấp cho bạn chức năng đó là một chéo giữa các lĩnh vực và phương pháp. | Chapter 3 Learning Just Enough C and Types and Members 81 Coding Fields and Properties A field is a variable that is a member of a class type as opposed to variables that are declared inside of methods which are called local variables or locally scoped variables. Properties are type members that give you functionality that is a cross between fields and methods. You can read and write to a property just as you can to a field. Additionally you can define code that runs whenever you read to or write from a property similar to methods. The following sections define fields and properties. Declaring and Using Fields As stated a field is a variable that is a member of a class or some other container such as a struct which is very similar to a class . This provides the benefit of having the field and the data it contains available to all of the other members of the class as well as to any deriving classes via inheritance depending on the field s access modifier . To demonstrate how a field is declared and used the example in Listing 3-8 simulates a bank account that has a field of type decimal named currentBalance which holds an account balance. The class has two methods Credit and Debit. Credit increases the value of currentBalance and Debit decreases the value of currentBalance. Listing 3-8 Using fields and properties C using System using using using namespace FirstProgram class Program private decimal accountBalance 100m static void Main string args Program account new Program 100m 50m Balance 82 Microsoft Visual Studio 2010 A Beginner s Guide public void Credit decimal amount accountBalance amount public void Debit decimal amount accountBalance - amount public decimal CurrentBalance get return accountBalance set if value 0 charge fee accountBalance value VB Module Modulel Private Dim accountBalance As Decimal 100 Sub Main .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.