Indexed class / list

R

Registered User

Yes, yes! Zach, PLEASE explain what you mean by "indexed class." That should
go a long way towards helping us answer your question.
Schematically it would allow doing like so:

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.
The Employee type shown above does not resemble a real-world model of
an employee.
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 :)
As abstract as the 'schematic' is input and output are not 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.
 
Z

Zach

I simply asked for help to create an indexed class called ...

- snip -
I've been following this thread and from the beginning it has not been
clear what you mean by 'an indexed class'. The code in the original
post used indexes into arrays. The contents are only indexed by virtue
of the container.

Yes, yes! Zach, PLEASE explain what you mean by "indexed class." That should
go a long way towards helping us answer your question.
Schematically it would allow doing like so:

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.
The Employee type shown above does not resemble a real-world model of
an employee.
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 :)
As abstract as the 'schematic' is input and output are not 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.

The get; sets; are erroring out on compile

using System;
using System.Collections.Generic;
using System.Text;

namespace Last
{
class Program
{
static void Main(string[] args)
{
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);
}

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;}
}
}
}
 
Z

Zach

[...]However, if the essence of the miscommunication is the term
"indexed class" that I have been using, by it I mean a user defined
class[index]. Zach.

I do not believe that the _essence_ of the miscommunication is your use
of that phrase. It's simply one facet of a broader problem.

I would say that at this point, one of the biggest factors is the lack
of any response whatsoever from you regarding the code examples that
have been suggested to you. You've made no comment one way or the other
about the examples, to provide any clue whether any of us are on the
right track or not.

You have people here willing to work with you to figure out what the
heck you actually mean. But it's a two-way street. If you aren't willing
to cooperate and provide the necessary feedback, we're not going to make
any progress.

Pete

I am very grateful for the responses I have been getting. I have been
doing my level best to respond appropriately. My inability to come
forward with what would have been considered appropriate is as
frustrating for me as it is for others.
 
Z

Zach

[...]However, if the essence of the miscommunication is the term
"indexed class" that I have been using, by it I mean a user defined
class[index]. Zach.

I do not believe that the _essence_ of the miscommunication is your use
of that phrase. It's simply one facet of a broader problem.

I would say that at this point, one of the biggest factors is the lack
of any response whatsoever from you regarding the code examples that
have been suggested to you. You've made no comment one way or the other
about the examples, to provide any clue whether any of us are on the
right track or not.

You have people here willing to work with you to figure out what the
heck you actually mean. But it's a two-way street. If you aren't willing
to cooperate and provide the necessary feedback, we're not going to make
any progress.

Pete

I am very grateful for the responses I have been getting. I have been
doing my level best to respond appropriately. My inability to come
forward with what would have been considered appropriate is as
frustrating for me as it is for others.
What Registered User has posted, shows the direction in which I was
searching. I have tried to sort out his code so it will compile,
hopefully in the way he intended. I am left with a a couple of errors. I
have posted the sorted out coded.
 
Z

Zach

I simply asked for help to create an indexed class called ...

- snip -
I've been following this thread and from the beginning it has not been
clear what you mean by 'an indexed class'. The code in the original
post used indexes into arrays. The contents are only indexed by virtue
of the container.

Yes, yes! Zach, PLEASE explain what you mean by "indexed class." That should
go a long way towards helping us answer your question.
Schematically it would allow doing like so:

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.
The Employee type shown above does not resemble a real-world model of
an employee.
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 :)
As abstract as the 'schematic' is input and output are not 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.

A.G. I am very happy with your code. Many thanks. I thought there was
reason to do a little sorting out of it, to make it compile, and have
posted the results. Hopefully that is what you intended.

Zach.
 
Z

Zach

(FWIW, I have 30+ years experience designing and programming computers
at various levels ranging from COBOL business applications to CPU
architecture & microcode and have remained technical the entire time,
stubbornly resisting the occasional pressure to move to the dark side.
Before that I worked as an electronics technician for some 10 years both
in and out of the military (long before I ever went to college or even
saw a computer).

I am honestly and truly impressed by your commendable career. But in
whichever way a person might be superior to me -- and there will be many
-- that does not give that person the right to publicly say whatever he
likes impunitively.
 
R

Registered User

On 12/16/2011 2:36 PM, Registered User wrote:
- snip -
example using a simple array :

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"
}
};

The get; sets; are erroring out on compile
- snip -
Sometimes the punctuation in a code sample can be difficult to
read.The code below contains six semicolons, while the code above uses
two semicolons and two commas. Correct these errors and your code will
compile.
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";
}
An longer version of the snippet of example code is :

Employee[] employees = new Employee[2];
// create an Employee object
Employee employee = new Employee();
// set the Name property
employee.Name = "Foo";
// create a Job object
Job job = new Job();
// set the Name property
job.Name = "some job";
// assign the Job object to the Employee object's Job property
employee.Job = job;
// assign employee to array
employees[0] = employee;

// as above
employee = new Employee();
employee.Name = "Bar";
job = new Job();
job.Name = "some other job";
employee.Job = job;
employees[1] = employee;

regards
A.G.
 
Z

Zach

Yes, I had already changed that :(
But all instances of set; set; are erroring out.
"must declare a body etc."

using System;
using System.Collections.Generic;
using System.Text;

namespace Last
{
class Program
{
static void Main(string[] args)
{
Employee[] employees = new Employee[2];
employees[0] = new Employee();
{
employees[0].Name = "Foo";
employees[0].TheJob = new Job().Name = "some job";
}

employees[1] = new Employee();
{
employees[1].Name = "Bar";
employees[1].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);
Console.ReadKey();
}

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;}
}
}
}
 
G

Gene Wirchenko

I am honestly and truly impressed by your commendable career. But in
whichever way a person might be superior to me -- and there will be many
-- that does not give that person the right to publicly say whatever he
likes impunitively.

Read this:

Then write your questions according to it.

Sincerely,

Gene Wirchenko
 
Z

Zach

This seems to do the trick:


using System;
using System.Collections.Generic;
using System.Text;

namespace Last
{
class Program
{
static void Main(string[] args)
{
Employee[] employees = new Employee[2];
employees[0] = new Employee();
{
employees[0].Name = "Foo";
employees[0].TheJob.Name = "some job";
}

employees[1] = new Employee();
{
employees[1].Name = "Bar";
employees[1].TheJob.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);
Console.ReadKey();
}

public class Job
{
public string Name;
}

public class Person
{
public string Name;
}

public class Employee:person
{
public Employee() : base() { }
public Job TheJob = new Job();
}
}
}
 
Z

Zach

If you are not using the latest version of C# (as your stated concern
here suggests you are not), you should share that information with the
people trying to help you.

You also _must_ provide _exact_ error messages. I guarantee you that the
compiler did not literally emit an error reading "must declare a body
etc.".

In any case, I'm bewildered as to how we went from your initial
objection to wrapping the data in a new type, to you deciding that what
was previously an objection is now exactly the question you were looking
for an answer to.

Pete
Pete, this was my adstruction to my query
"Schematically it would allow doing this":

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.

elsewhere:

emp[0] ---> output the value for person and job
emp[1] ---> output the value for person and job
etc.

This code does exactly that:

using System;
using System.Collections.Generic;
using System.Text;

namespace Last
{
class Program
{
static void Main(string[] args)
{
Employee[] employees = new Employee[2];
employees[0] = new Employee();
{
employees[0].Name = "Foo";
employees[0].TheJob.Name = "some job";
}

employees[1] = new Employee();
{
employees[1].Name = "Bar";
employees[1].TheJob.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);
Console.ReadKey();
}

public class Job
{
public string Name;
}

public class Person
{
public string Name;
}

public class Employee:person
{
public Employee() : base() { }
public Job TheJob = new Job();
}
}
}
 
Z

Zach

On 12/16/2011 2:36 PM, Registered User wrote:
- snip -
example using a simple array :

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"
}
};

The get; sets; are erroring out on compile
- snip -
Sometimes the punctuation in a code sample can be difficult to
read.The code below contains six semicolons, while the code above uses
two semicolons and two commas. Correct these errors and your code will
compile.
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";
}
An longer version of the snippet of example code is :

Employee[] employees = new Employee[2];
// create an Employee object
Employee employee = new Employee();
// set the Name property
employee.Name = "Foo";
// create a Job object
Job job = new Job();
// set the Name property
job.Name = "some job";
// assign the Job object to the Employee object's Job property
employee.Job = job;
// assign employee to array
employees[0] = employee;

// as above
employee = new Employee();
employee.Name = "Bar";
job = new Job();
job.Name = "some other job";
employee.Job = job;
employees[1] = employee;

regards
A.G.
I posted the results elsewhere, sorry.
Thank you very much for helping me out.
Zach.

using System;
using System.Collections.Generic;
using System.Text;

namespace Last
{
class Program
{
static void Main(string[] args)
{
Employee[] employees = new Employee[2];
employees[0] = new Employee();
{
employees[0].Name = "Foo";
employees[0].TheJob.Name = "some job";
}

employees[1] = new Employee();
{
employees[1].Name = "Bar";
employees[1].TheJob.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);
Console.ReadKey();
}

public class Job
{
public string Name;
}

public class Person
{
public string Name;
}

public class Employee:person
{
public Employee() : base() { }
public Job TheJob = new Job();
}
}
}
 
Z

Zach

On 12/16/11 11:44 AM, Zach wrote:
If you are not using the latest version of C# (as your stated concern
here suggests you are not), you should share that information with the
people trying to help you.

You also _must_ provide _exact_ error messages. I guarantee you that the
compiler did not literally emit an error reading "must declare a body
etc."

I have not seen anyone indicate their version of C#, so I was unaware
that would be expected of me. I have Visual Studio 2005. If that is what
you mean. I thought that "must declare a body etc." contained the
keyword of the error condition.
In any case, I'm bewildered as to how we went from your initial
objection to wrapping the data in a new type, to you deciding that what
was previously an objection is now exactly the question you were looking
for an answer to.

Would you please point out where I did that, because I am unaware of
this. If I unknowingly did that, I apologize. I try and tread as softly
as I can here anyway, because experiences here have conditioned me to do so.

Regards,
Zach.
 
Z

Zach

Pete, this was my adstruction to my query

There's no such word as "adstruction".
"Schematically it would allow doing this":

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.

elsewhere:

emp[0] ---> output the value for person and job
emp[1] ---> output the value for person and job
etc.

This code does exactly that:

So do both code examples I posted, as well as the others. The problem is
that "exactly that" is so vague, no one knows what you mean.

Furthermore, as soon as you wrote "lump the two indexed objects in my
trial example together into one object" you got a prompt reply from Jeff
showing _exactly_ how to do that, and yet you responded with "there
doesn't appear to be an answer to [my question]".

In other words, you initially told us that you did _not_ want to combine
the two values into a single data structure, in spite of writing
something that seemed to say you did want to do that. Then finally,
after much back and forth, it turns out you _did_ want to do that all
along.

I appreciate that it must be frustrating for you to fail to express your
question clearly enough for it to be answered. But I hope you are
cognizant of what things you need to do differently in the future to
avoid such frustration. You seem at times to be _actively_ hindering
attempts by others to decipher what you mean.

Programming is an activity requiring precision and unambiguity. You
should apply to your question-asking the same precise, unambiguous
approach that is required by programming.

Pete

"You seem at times to be _actively_ hindering attempts by others to
decipher what you mean."

Peter, things are not always what they seem. I think one should always
give the other person an advance of trust and presuppose that they are
acing in a good faith.

"I appreciate that it must be frustrating for you to fail to express
your question clearly enough for it to be answered. But I hope you are
cognizant of what things you need to do differently in the future to
avoid such frustration."

I have much respect for the way contributors respond to queries here,
and have in the past, and will certainly in the future, do my utmost to
communicate my query clearly.

Thank you, and the others, for your help.

Regards,
Zach.
 
Z

Zach

I have not seen anyone indicate their version of C#, so I was unaware
that would be expected of me.

As I wrote (I'll make it bigger this time, so you can read it):

"IF YOU ARE NOT USING THE LATEST VERSION OF C#…"

Most of the rest of us are. The default assumption is that you are. If
you are not, THEN you should share that information.
I have Visual Studio 2005. If that is what
you mean. I thought that "must declare a body etc." contained the
keyword of the error condition.

We can try to infer the actual error message from what you wrote. And
sometimes we will be successful. That's not the point. The point is that
you already have the exact error message. There's no reason to force
people to guess, when you can just type the exact error message.
Would you please point out where I did that, because I am unaware of
this. If I unknowingly did that, I apologize. I try and tread as softly
as I can here anyway, because experiences here have conditioned me to do
so.

As I mentioned elsewhere, when Jeff proposed that you do exactly that
(wrap the data in a new type) your response was "there doesn't appear to
be an answer to [my question]". The clear implication being that Jeff's
answer did not address your question.

Pete

Thank you for pointing this out to me. I regret the misunderstanding.

Zach.
 
Z

Zach

No one is doing otherwise. I take it as granted that you are not
intentionally hindering the attempts. But the fact remains that you are,
with or without intent.

Sometimes it's not good enough to not be intentionally doing the wrong
thing. Sometimes, you need to make a more concerted effort to do the
_right_ thing.

Pete
Pete, I would like to ad a PS.

I am sorry about yesterday. I set out with an indexer, like below. It
contains data. Suppose data were to be changed to "person", my question
was how I could ad say "job", for the code to be able to manipulate both
person and job, rather than just person. I somehow got totally mind
boggled during the discussion with you guys, unable to deal with the
simplest code lines. I had said at the outset that I wasn't looking for
a container of employee-objects of some sort, with which I ended up.
Don't know what happened. It has been a jolly bad experience. I have
found it very difficult to be in a discussion where one wrong word
causes heaven to explode.

Zach

uusing System;
using System.Collections.Generic;
using System.Text;

namespace IndexedClass
{
class Program
{
static void Main(string[] args)
{
int index_size = 5;
Indexer Indxr = new Indexer(index_size);
for (int i = 0; i < index_size; i++)
{
Indxr = i.ToString();
Console.WriteLine(" {0}: {1}", i, Indxr);
}
Console.ReadKey();
}
}
public class Indexer
{
private string[] data;
public string this[int Position]{ get { return data[Position];}
set { data[Position] = value; }}

public Indexer(int index_size)
{
data = new string[index_size];
}
}
}
 
A

Arne Vajhøj

I am sorry about yesterday. I set out with an indexer, like below. It
contains data. Suppose data were to be changed to "person", my question
was how I could ad say "job", for the code to be able to manipulate both
person and job, rather than just person. I somehow got totally mind
boggled during the discussion with you guys, unable to deal with the
simplest code lines. I had said at the outset that I wasn't looking for
a container of employee-objects of some sort, with which I ended up.
Don't know what happened. It has been a jolly bad experience. I have
found it very difficult to be in a discussion where one wrong word
causes heaven to explode.

I provided an example showing what you could do to dual index.

But you did never even comment on that.

Arne
 
Z

Zach

I provided an example showing what you could do to dual index.

But you did never even comment on that.

Arne
Arne,

Thank you for drawing my attention to your post. I am afraid that I seem
to have spent yesterday in utter confusion. An unpleasant situation was
unfolding around me while I was working with you guys and I guess I lost
my nuts. You have put in a lot of effort to help, for which I thank you
sincerely, and I _apologize _for _not _responding, which is absolutely
"pas comme il faut".

In fact I did try your code, and got a long list of errors.
Line 79 onwards: "A new expression requires () or [] after type"
Line 8 E.Person.Name.get must declare a body because it is not marked
abstract or extern.
more similar to the previous line 8 error.

I have VS 2005, and it would appear that given VS 2010 is now in use, it
might be the VS that I am using, which is causing the errors. I think
you are using VS'10 syntax with which I am not yet familiar. Hence I am
finding it hard to figure out what you are doing. VS costs 1000€ in this
country, so I will have to have a good think about what to do next.

Please accept my apologies.
Regards,
Zach
 
A

Arne Vajhøj

I provided an example showing what you could do to dual index.

But you did never even comment on that.

Thank you for drawing my attention to your post. I am afraid that I seem
to have spent yesterday in utter confusion. An unpleasant situation was
unfolding around me while I was working with you guys and I guess I lost
my nuts. You have put in a lot of effort to help, for which I thank you
sincerely, and I _apologize _for _not _responding, which is absolutely
"pas comme il faut".

In fact I did try your code, and got a long list of errors.
Line 79 onwards: "A new expression requires () or [] after type"
Line 8 E.Person.Name.get must declare a body because it is not marked
abstract or extern.
more similar to the previous line 8 error.

I have VS 2005, and it would appear that given VS 2010 is now in use, it
might be the VS that I am using, which is causing the errors. I think
you are using VS'10 syntax with which I am not yet familiar. Hence I am
finding it hard to figure out what you are doing. VS costs 1000€ in this
country, so I will have to have a good think about what to do next.

It is.

I am just lazy and initialized things the easiest way using .NET 3.5
features.

But the core can easily be converted back to .NET 2.0.

using System;
using System.Collections.Generic;

namespace E
{
public class Person
{
private string _name;
private string _address;
public Person(string name, string address)
{
_name = name;
_address = address;
}
public string Name
{
get { return _name; }
set { _name = value; }
}
public string Address
{
get { return _address; }
set { _address = value; }
}
public override string ToString() { return "{" + Name + "," +
Address + ")"; }
}
public class Job
{
private string _title;
private decimal _salary;
public Job(string title, decimal salary)
{
_title = title;
_salary = salary;
}
public string Title
{
get { return _title; }
set { _title = value; }
}
public decimal Salary
{
get { return _salary; }
set { _salary = value; }
}
public override string ToString() { return "{" + Title + "," +
Salary + ")"; }
}
public class PersonList
{
private List<Person> data = new List<Person>();
public void Add(Person p)
{
data.Add(p);
}
public Person this[int ix]
{
get { return data[ix]; }
}
}
public class JobList
{
private List<Job> data = new List<Job>();
public void Add(Job j)
{
data.Add(j);
}
public Job this[int ix]
{
get { return data[ix]; }
}
}
public class Index
{
private int _ix;
public Index(int ix)
{
_ix = ix;
}
public int Ix
{
get { return _ix; }
set { _ix = value; }
}
}
public class PersonIndex : Index
{
public PersonIndex(int ix) : base(ix) { }
}
public class JobIndex : Index
{
public JobIndex(int ix) : base(ix) { }
}
public class EmployeeList
{
private PersonList persons = new PersonList();
private JobList jobs = new JobList();
public void Add(Person p, Job j)
{
persons.Add(p);
jobs.Add(j);
}
public Person GetPerson(int ix)
{
return persons[ix];
}
public Job GetJob(int ix)
{
return jobs[ix];
}
public Person this[PersonIndex ix]
{
get { return GetPerson(ix.Ix); }
}
public Job this[JobIndex ix]
{
get { return GetJob(ix.Ix); }
}
}
public class Program
{
public static void Main(string[] args)
{
EmployeeList lst = new EmployeeList();
lst.Add(new Person("A A", "A road 123"), new
Job("Developer", 10000.00m));
lst.Add(new Person("B B", "B ave 456"), new Job("Tester",
9000.00m));
Console.WriteLine(lst.GetPerson(0));
Console.WriteLine(lst.GetJob(1));
Console.WriteLine(lst[new PersonIndex(0)]);
Console.WriteLine(lst[new JobIndex(1)]);
Console.ReadKey();
}
}
}

Arne
 
Z

Zach

On 12/17/2011 5:40 AM, Zach wrote:
I am sorry about yesterday. I set out with an indexer, like below. It
contains data. Suppose data were to be changed to "person", my question
was how I could ad say "job", for the code to be able to manipulate
both
person and job, rather than just person. I somehow got totally mind
boggled during the discussion with you guys, unable to deal with the
simplest code lines. I had said at the outset that I wasn't looking for
a container of employee-objects of some sort, with which I ended up.
Don't know what happened. It has been a jolly bad experience. I have
found it very difficult to be in a discussion where one wrong word
causes heaven to explode.

I provided an example showing what you could do to dual index.

But you did never even comment on that.

Thank you for drawing my attention to your post. I am afraid that I seem
to have spent yesterday in utter confusion. An unpleasant situation was
unfolding around me while I was working with you guys and I guess I lost
my nuts. You have put in a lot of effort to help, for which I thank you
sincerely, and I _apologize _for _not _responding, which is absolutely
"pas comme il faut".

In fact I did try your code, and got a long list of errors.
Line 79 onwards: "A new expression requires () or [] after type"
Line 8 E.Person.Name.get must declare a body because it is not marked
abstract or extern.
more similar to the previous line 8 error.

I have VS 2005, and it would appear that given VS 2010 is now in use, it
might be the VS that I am using, which is causing the errors. I think
you are using VS'10 syntax with which I am not yet familiar. Hence I am
finding it hard to figure out what you are doing. VS costs 1000€ in this
country, so I will have to have a good think about what to do next.

It is.

I am just lazy and initialized things the easiest way using .NET 3.5
features.

But the core can easily be converted back to .NET 2.0.

using System;
using System.Collections.Generic;
<snipped>

Arne,

Your code looks good. Thank you very much!!

I will need to digest your code and would like to get back to you after
I am done.

Regards,
Zach.

PS I had a peep at your website, I like your animals. Is Cranston in
Denmark or in the States? My site is pearltree.org, no personal stuff
though.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top