Simple indexer example

Source: Internet
Author: User

The indexer is also called an attribute with parameters. The declaration method is very similar to the attribute.

 

 

Code

  //  Example of Indexer  
Class Group
{
Public Const Int Maxnum = 8 ;
Private String [] Memeber;

Public String This [ Int Idx] // Define Indexer
{
Get { Return Memeber [idx];}
Set {Memeber [idx] = Value ;}
}

Public Group ()
{
Memeber = New String [Maxnum];
}
Static Void Main ( String [] ARGs)
{
// Note that group is an instance of a class. Because the indexer is defined, you can assign values and values like arrays.
Group = New Group ();
Group [ 0 ] = " Zhang San " ;
Group [ 1 ] = " Li Si " ;
Group [ 2 ] = " Wang Wu " ;
Group [ 3 ] = " Money 6 " ;
Group [ 4 ] = " Zhao Qi " ;
Group [ 5 ] = " Sun Ba " ;
For ( Int I = 0 ; I < Group. maxnum; I ++ )
{
Console. writeline (group [I]); // Value
}
}
}

 

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.