Mega Code Archive

 
Categories / C# / Collections Data Structure
 

Class array

/* Learning C#  by Jesse Liberty Publisher: O'Reilly  ISBN: 0596003765 */  using System;  namespace ArrayDemo  {      // a simple class to store in the array      class Employee      {          private int empID;          // constructor          public Employee(int empID)          {              this.empID = empID;          }          public override string ToString()          {              return empID.ToString();          }      }     public class TesterClassArray     {        public void Run()        {            int[] intArray;            Employee[] empArray;            intArray = new int[5];            empArray = new Employee[3];            // populate the array            for (int i = 0;i<empArray.Length;i++)            {                empArray[i] = new Employee(i+5);            }            Console.WriteLine("The int array...");            for (int i = 0;i<intArray.Length;i++)            {                Console.WriteLine(intArray[i].ToString());            }            Console.WriteLine("\nThe employee array...");            for (int i = 0;i<empArray.Length;i++)            {                Console.WriteLine(empArray[i].ToString());            }        }        [STAThread]        static void Main()        {           TesterClassArray t = new TesterClassArray();           t.Run();        }     }  }