C # Indexer: Take an example of an element in a collection or array _ "Go"

Source: Internet
Author: User

Garmmar:

[Access modifier] Data type this[parameter list]

{

Get

{Gets the contents of the indexer}

Set

{Set the contents of the indexer}

}

Eg:

1<span style="font-size:14px;">usingSystem; 2     usingSystem.Collections.Generic; 3     usingSystem.Text; 4       5     namespaceindexerusing6     {  7         classPhoto8         {  9              Ten             Private stringname;  One        A              Public stringName -             {   -                 Get{returnname;}  the                 Set{name =value;}  -             }   -              PublicPhoto () {} -              PublicPhoto (stringname) +             {   -                  This. Name =name;  +             }   A         }   at         classAlbum -         {   -             Privatephoto[] _photos;  -              PublicAlbum () -             { }   -              PublicAlbum (intcount) in             {   -_photos =NewPhoto[count];  to             }   +              PublicPhoto This[intIndex] -             {   the                 Get   *                 {   $                     if(Index <0|| Index >_photos. Length)Panax Notoginseng                         return NULL;  -                     Else   the                         return_photos[index];  +                 }   A                 Set   the                 {   +                     if(Index <0|| Index >_photos. Length) -                         return;  $                     Else   $_photos[index] =value;  -                 }   -             }   the         }   -       Wuyi         class Program the         {   -             Static voidMain (string[] args) Wu             {   -Album Album =NewAlbum (3);  AboutPhoto photo1 =NewPhoto ("Wang Yunpeng");  $Photo Photo2 =NewPhoto ("Huangliyun");  -Photo Photo3 =NewPhoto ("Li Wenping");  -album[0] =photo1;  -album[1] =Photo2;  Aalbum[2] =Photo3;  +Console.WriteLine ("Enter first Photo: {0}", album[0].  Name);  the        -             }   $         }   the     }   the</span>

C # Indexer: Take an example of an element in a collection or array _ "Go"

Related Article

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.