Indexes in c#

using System.Collections.Generic;

namespace CSharpBasics
{
    //WE CANNOT HAVE STATIC INDEXERS IN C#
    class Indexes
    {
        List<int> L = new List<int>();
        
        public int this[int i]
        {
            get 
            {
                return L[i];
            }
            set 
            {
                L.Add(value);
            }
        }

        protected string this[string i]
        {
            get
            {
                return "hello";
            }
            set
            {
                //Do nothing;
            }
        }
    }
}
Add Comments :

Login

Register