Programming C# 2nd Edition phần 4

Mảng này được in, và sau đó được truyền cho phương pháp (), nơi mà nó được in một lần nữa để thấy rằng các mảng chính nó đã bị đảo ngược:Đây là thông qua các phương pháp (). Sau đó () hạnh phúc sắp xếp chúng theo thứ tự bảng chữ cái: | Programming C 2nd Edition Output Value Value Value Value Value Value Value Value Value Value Value Value Value Value Value Value Value Value Value Value Value Value Value Value Who is John Galt Galt John is Who We Hold These Truths To Be Self Evident Be Evident Hold Self These To Truths We The example begins by creating myArray an array of strings with the words Who is John Galt This array is printed and then passed to the method where it is printed again to see that the array itself has been reversed Value Galt Value John Value is Value Who Similarly the example creates a second array myOtherArray containing the words We Hold These Truths To Be Self Evident This is passed to the method. Then happily sorts them alphabetically Value Value Value Value Value Value Value Value Be Evident Hold Self These To Truths We 172 Programming C 2nd Edition Indexers There are times when it is desirable to access a collection within a class as though the class itself were an array. For example suppose you create a list box control named myListBox that contains a list of strings stored in a one-dimensional array a private member variable named myStrings. A list box control contains member properties and methods in addition to its array of strings. However it would be convenient to be able to access the list box array with an index just as if the list box were an array. For example such a property would permit statements like the following string theFirstString myListBox 0 string theLastString myListBox Length-1 An indexer is a C construct that allows you to access collections contained by a class using the familiar syntax of arrays. An indexer is a special kind of property and includes get and set methods to specify its behavior. You declare an indexer property within a class using the following syntax type this type argument get set The return type determines the type of object that will be returned by the indexer while the type argument .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã 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.