Tuesday 9 August 2016

Indexers C Charp

class IndexeCls
    {
        private string[] namelist = new string[size];
        static public int size = 3;
        public IndexeCls()
        {
            for (int i = 0; i < size; i++)
                namelist[i] = "N. A.";
        }


        public string this[int index]
        {
            get
            {
                string tmp;

                if (index >= 0 && index <= size - 1)
                {
                    tmp = namelist[index];
                }
                else
                {
                    tmp = "";
                }

                return (tmp);
            }
            set
            {
                if (index >= 0 && index <= size - 1)
                {
                    namelist[index] = value;
                }
            }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            IndexeCls ob=new IndexeCls();
            ob[0]="Girfa";
            ob[1]="Student";
            ob[2]="Help";
            for(int i=0;i<3;i++)
                Console.WriteLine(ob[i]);
            Console.ReadKey();
        }
    }

Next Topic

No comments:

Post a Comment