Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 188
  • Last Modified:

Commenting code help

Please help me understand this code...


namespace Programming_CSharp
{
   using System;
 
   // a simple class to store in the array
   public class Employee
   {
      // a simple class to store in the array
      public Employee(int empID)
      {
         this.empID = empID;
      }
      public override string ToString( )
      {
         return empID.ToString( );
      }
      private int empID;
   }
   public class Tester
   {
      static void Main( )
      {
         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);
         }
           
         for (int i = 0;i<intArray.Length;i++)
         {
            Console.WriteLine(intArray[i].ToString( ));
         }

         for (int i = 0;i<empArray.Length;i++)
         {
            Console.WriteLine(empArray[i].ToString( ));
         }
      }
   }
}
0
chilled2003
Asked:
chilled2003
1 Solution
 
tinchosCommented:
The class Employee is a class that just holds the employeeId (Which is an integer).

The tester class is the one that holds main.

Main creates 2 arrays, one of ints and the other of Employees.

Then it fills the employee array creating employees whose id is 5, 6 and 7 respectively.

After that it prints all the elements of the integer array (Which has not been initialized by the way).

and finally it prints all the elements of the Employee array.

The output of this final array would be

5, 6, 7

As the toString method of the employee class prints the EmployeeId.

Hope this helps

Tincho
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now