using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Properties
{
    class Examples41_43
    {
        public static void UseIndexedList()
        {
            // Listing 3-41
            var numbers = new List<int> { 1, 2, 1, 4 };
            numbers[2] += numbers[1];
            Console.WriteLine(numbers[0]); 
        }

        // Listing 3-42
        public class Indexed
        {
            public string this[int index]
            {
                get
                {
                    return index < 5 ? "to" : "tamto";
                }
            }
        }

        public static void UseCustomIndexer()
        {
            var i = new Indexed();
            Console.WriteLine(i[0]);
            Console.WriteLine(i[1]);
            Console.WriteLine(i[2]);
            Console.WriteLine(i[3]);
            Console.WriteLine(i[4]);
            Console.WriteLine(i[5]);
            Console.WriteLine(i[6]);
        }

        //// Commented out because it illustrates an error
        //// Listing 3-43
        //public string X[int index]  // tego kodu nie uda się skompilować!
        //{
        //    get ... 
        //} 
    }
}
