TAILIEUCHUNG - Lesson 10: Properties

This lesson teaches C# Properties. | Tutorial Page 1 of 6 Using Excellent Tools to Write Web Applications Tar the .NET Common Language Runtime CLR Home Up Lesson01 Lesson02 Lesson03 Lesson04 Les Lesson06 Lesson07 Lesson08 Lesson09 Lesson10 Les Lesson12 Lesson13 On sale Now C Unleashed is an indepth guide for intermediate to advanced software developers to learn the C programming language and serve as a desktop reference. The C Station Tutorial by Joe Mayo 02 10 01 Lesson 10 Properties This lesson teaches C Properties. Our objectives are as follows Understand What Properties Are For. Implement a Property. Create a Read-Only Property. Create a Write-Only Property. Properties are a new language feature introduced with C . They provide the opportunity to protect a field in a class by reading and writing to it through the property. In other languages this is accomplished by programs implementing specialized getter and setter methods. C properties enable this type of protection while also letting you access the property just like it was a field. To get an appreciation for what properties accomplish let s take a look at how to provide field encapsulation by traditional methods. Listing 10-1. An Example of Traditional Class Field Access using System public class PropertyHolder private int someProperty 0 public int getSomeProperty return someProperty public void setSomeProperty int propValue someProperty propValue http Tutorials 6 24 2002 Tutorial Page 2 of 6 public class PropertyTester public static int Main string args PropertyHolder propHold new PropertyHolder 5 Property Value 0 return 0 Listing 10-1 shows the traditional method of accessing class fields. The PropertyHolder class has the field we re interested in accessing. It has tw methods getSomeProperty and setSomeProperty. The getSomeProperty method returns the value of the someProperty field. The setSomeProperl method sets the value of

TỪ KHÓA LIÊN QUAN
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.