Prashant Jadhav

Prashant Jadhav

  • NA
  • 38
  • 14.4k

indexer

Aug 3 2014 9:55 AM
hey guys i was creating indexer and i had some issue i didnt got any compile or runtime error but there was no out put 
here is that coding tell me where i made wrong coding.
 
using System;

namespace ConsoleApplication13
{
    class employee
    {
        public string name;
        public string branch;
        public int ID;
        
    }
    class employees
    {
        
        employee[] empl=new employee[3];
        public employee this[int x]
        {
            get
            {
                switch(x)
                
                {
                    case 0: empl[0] = new employee();
                             return empl[0];
                    case 1: empl[1] = new employee();
                            return empl[1];
                    case 2: empl[2] = new employee();
                            return empl[2];
                }
                return null;
            }

        }

       

    }
    class Program
    {
        static void Main(string[] args)
        {
            employees e=new employees();
            e[0].name="prashant";
            string a=e[0].name;
            Console.WriteLine("{0}",a);
            Console.ReadLine();
        }
    }
}

Answers (1)