C # syntax exercise (13): class [5]-Indexer

Source: Internet
Author: User
The indexer allows you to easily use the Array (or set) members in the class:
Using system; Class myclass {private float [] FS = new float [3] {1.1f, 2.2f, 3.3f};/* attribute */Public int length {get {return FS. length ;}set {FS = new float [value] ;}/ * indexer */public float this [int N] {get {return FS [N];} set {FS [N] = value ;}} class program {static void main () {myclass OBJ = new myclass (); For (INT I = 0; I

Other values can be used as index types:

Using system; Class myclass {public int this [String STR] {get {return Str. length ;}} class program {static void main () {myclass OBJ = new myclass (); console. writeline (OBJ ["123"]); // 3 console. writeline (OBJ ["ABCD"]); // 4 console. readkey ();}}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.