Indexer

Source: Internet
Author: User

I understand that the indexer is an access mechanism. For example, if you want to access an element of an array in the category class under normal circumstances, the access is like this: an object --> object name is generated by the instance. array name [index value]; if you add an index that is declared by the this keyword to the array in the class. in this way, you can create an object --> object name [index value]. you can access that element.

Of course, the code in the so-called indexer is also self-written, and the types and numbers of indexer parameters can be defined by themselves, so you can Index in different ways to find the data to be returned.

Example: by associating an indexer to an array, you can access

1 class A 2 {3 private int [] Arr = {1, 2, 3, 4, 5, 6, 7 }; 4 public int this [int I] 5 {6 get {return Arr [I];} 7 set {value = Arr [I];} 8} 9} 10 11 class Program12 {13 static void Main (string [] args) 14 {15 16 A = new a (); 17 Console. writeLine (a [3]); 18 Console. read (); 19 20}

At present, I have not realized any other overbearing aspects of the indexer.

It should be awesome.

Indexer

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.