Simple Indexer

<< Click to Display Table of Contents >>

Navigation:  Início >

Simple Indexer

Previous pageReturn to chapter overviewNext page

  class Cliente

   {

      private string[] values = new string[] { "Angelina", "Izabella", "Flávia", "Alessandra", "Keylee", "Inara", "Zoe" };

 

      public string this[int index]

       {

          get { return values[index]; }

          set { values[index] = value; }

       }

 

      public int Count { get { return values.Length; } }

   }

 

  class Program

   {

      public static void Main()

       {

          Cliente cliente = new Cliente();

          Console.WriteLine(cliente[1]);

          Console.WriteLine(cliente[0]);

          Console.WriteLine(cliente[2]);

          Console.WriteLine(cliente.Count);

       }

   }