1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Runtime.InteropServices;5 usingSystem.Text;6 7 namespaceclasstrining8 {9 classDemoTen { One //=============== Property ============================================= A //declaring private fields - Private string_name ="Mike"; - /// <summary> the ///declaring Properties - /// </summary> - Public stringName - { + Get - { + //returns the private field value of the Declaration A return_name; at } - Set - { - //use fields to save user-set values -_name =value; - } in } - //=============== Property ============================================= to + - //=============== Indexer ============================================= the //declaring an array of strings * string[] Strarray =New string[ -]; $ /// <summary>Panax Notoginseng ///declares a string type indexer this is used to manipulate an array of strings and to find values by index - /// </summary> the /// <param name= "i" ></param> + /// <returns></returns> A Public string This[inti] the { + Get - { $ //returns the specified index value of an array $ returnStrarray[i]; - } - Set the { - //change the value of the index position with the array and save the user setting valueWuyiStrarray[i] =value; the } - } Wu //=============== Indexer ============================================= - About } $ - - classMijk - { A Private stringName ="Lihong"; + the - Public stringName $ { the Get the { the returnname; the } - Set in { theName =value; the } About } the the Private string[] Meli =New string[ -]; the + - Public string This[inti] the {Bayi Get the { the returnMeli[i]; - } - Set the { theMeli[i] =value; the } the } - the Public voidTest () the { themeli[0] ="Hello";94meli[1] ="kity"; themeli[2] ="CSharp"; themeli[ A] ="Studio"; the 98 stringstr = meli[2]; About - 101meli[ About] ="NOKIA";102 103 stringNokia = meli[ About];104 } the 106 107 108 109 the }111 the 113 the}
C # Indexer