TAILIEUCHUNG - Lesson 12: Structs

This lesson teaches C# Structs. | Tutorial Page 1 of 3 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 01 19 02 Lesson 12 Structs This lesson teaches C Structs. Our objectives are as follows Understand the Purpose of structs. Implement a struct. Use a struct. A struct allows you to create new value-type objects that are similar to the built-in types int float bool etc. . When would you use a struct instead of a class Think about how the built-in types are used. They have values and distinct operations to manipulate those values. If you have a need to create an object that behaves in this manner consider implementing it as a struct. Later in this article I ll explain a couple rule for using structs which will give you a better idea of when to use them. In the meantime here s an example. Listing 12-1. Example of a struct using System struct Point public int x public int y public Point int x int y x y public Point Add Point pt http Tutorials 6 24 2002 Tutorial Page 2 of 3 Point newPt x y return newPt III summary III Example of declaring and using a struct III Isummary class StructExample static void Main string args Point pt1 new Point 1 1 Point pt2 new Point 2 2 Point pt3 pt3 pt2 pt3 0 1 Listing 12-1 shows how to declare and use a struct. It s easy to tell that a type is a struct because of the keyword struct used in it s definition. Th basic layout of a struct is much like a class but with differences which will be explained in following paragraphs. The Point struct has a constructor which initializes it s fields to the x

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.