R
Registered User
The Employee type shown above does not resemble a real-world model ofSchematically it would allow doing like so:Yes, yes! Zach, PLEASE explain what you mean by "indexed class." That should
go a long way towards helping us answer your question.
Employee emp = new Employee(index_size);
emp[0] <--- input the value for person and job
emp[1] <--- input the value for person and job
etc.
an employee.
As abstract as the 'schematic' is input and output are not fixations;elsewhere:
emp[0] ---> output the value for person and job
emp[1] ---> output the value for person and job
etc.
"input" and "output" are fixations
they represent objects containing a person value and a job value. This
type is where the Employee moniker should hang.
public class Job
{
public string Name { get; set; }
}
public class Person
{
public string Name { get; set; }
}
public class Employee : Person
{
public Employee() : base() {}
public Job TheJob {get; set;}
}
The types above show that an Employee _is_ a Person and that an
Employee _has_ a member of type Job.
Employees seems a suitable name for a collection of Employee
instances. Such a collection can be implemented in multiple ways. An
example using a simple array :
Employee[] employees = new Employee[2];
employees[0] = new Employee()
{
Name = "Foo",
TheJob = new Job()
{
Name = "some job"
}
};
employees[1] = new Employee()
{
Name = "Bar",
TheJob = new Job()
{
Name = "some other job"
}
};
Console.WriteLine("The job of {0} is {1}",
employees[0].Name,
employees[0].TheJob.Name);
Console.WriteLine("The job of {0} is {1}",
employees[1].Name,
employees[1].TheJob.Name);
// the output of the lines above will be
The job of Foo is some job.
The job of Bar is some other job.
If the collection of Employee types is to be a member of another type,
the collection can be exposed using an indexer.
regards
A.G.