Solved

Commenting code help

Posted on 2003-10-28
1
183 Views
Last Modified: 2012-05-04
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
Comment
Question by:chilled2003
1 Comment
 
LVL 9

Accepted Solution

by:
tinchos earned 75 total points
ID: 9637056
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question