Indexed class / list

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.

<snipped>

Hi Arne, I believe this is shorter:)
does the same thing.

Zach

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

namespace analysis1
{
class Program
{
static void Main(string[] args)
{
EmployeeList lst = new EmployeeList();
lst.Add(new Person("A A", "A road 123"));
lst.Add(new Job("Fitter", "10000$"));

lst.Add(new Person("B B", "B ave 456"));
lst.Add(new Job("Tester", "234567$"));

Console.WriteLine(lst.PersonRetrieve(0).PersonString());
Console.WriteLine(lst.JobRetrieve(0).JobString());
Console.WriteLine(lst.PersonRetrieve(1).PersonString());
Console.WriteLine(lst.JobRetrieve(1).JobString());

Console.ReadKey();
}

public class PersonList
{
private List<Person> people = new List<Person>();
public void Add(Person p) { people.Add(p); }
public Person this[int px] { get { return people[px]; }
set { people[px] = value; } }
public Person PersonRetrieve(int py) { return people[py]; }
}

public class JobList
{
private List<Job> jobs = new List<Job>();
public void Add(Job j) { jobs.Add(j); }
public Job this[int jx] { get { return jobs[jx]; }
set { jobs[jx] = value; } }
public Job JobRetrieve(int jy) { return jobs[jy]; }
}

public class Person
{
string name;
string address;
public Person(string name, string address)
{
this.name = name;
this.address = address;
}
public string PersonString()
{
return string.Format ("Name {0} Address {1}",
name, address);
}
}

public class Job
{
string title;
string salary;
public Job(string title, string salary)
{
this.title = title;
this.salary = salary;
}
public string JobString()
{
return string.Format("Title {0} Salary {1}",
title, salary);
}
}

public class EmployeeList
{
private PersonList persons = new PersonList();
public void Add(Person p)
{
persons.Add(p);
}
public Person PersonRetrieve(int arg)
{
return persons.PersonRetrieve(arg);
}

private JobList jobs = new JobList();
public void Add(Job j)
{
jobs.Add(j);
}
public Job JobRetrieve(int arg)
{
return jobs.JobRetrieve(arg);
}
}
}
}
 
A

Arne Vajhøj

On 12/17/2011 9:02 PM, Arne Vajhøj wrote:
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.

<snipped>

Hi Arne, I believe this is shorter:)
does the same thing.
using System;
using System.Collections.Generic;
using System.Text;

namespace analysis1
{
class Program
{
static void Main(string[] args)
{
EmployeeList lst = new EmployeeList();
lst.Add(new Person("A A", "A road 123"));
lst.Add(new Job("Fitter", "10000$"));

lst.Add(new Person("B B", "B ave 456"));
lst.Add(new Job("Tester", "234567$"));

Console.WriteLine(lst.PersonRetrieve(0).PersonString());
Console.WriteLine(lst.JobRetrieve(0).JobString());
Console.WriteLine(lst.PersonRetrieve(1).PersonString());
Console.WriteLine(lst.JobRetrieve(1).JobString());

Console.ReadKey();
}

public class PersonList
{
private List<Person> people = new List<Person>();
public void Add(Person p) { people.Add(p); }
public Person this[int px] { get { return people[px]; }
set { people[px] = value; } }
public Person PersonRetrieve(int py) { return people[py]; }
}

public class JobList
{
private List<Job> jobs = new List<Job>();
public void Add(Job j) { jobs.Add(j); }
public Job this[int jx] { get { return jobs[jx]; }
set { jobs[jx] = value; } }
public Job JobRetrieve(int jy) { return jobs[jy]; }
}

public class Person
{
string name;
string address;
public Person(string name, string address)
{
this.name = name;
this.address = address;
}
public string PersonString()
{
return string.Format ("Name {0} Address {1}",
name, address);
}
}

public class Job
{
string title;
string salary;
public Job(string title, string salary)
{
this.title = title;
this.salary = salary;
}
public string JobString()
{
return string.Format("Title {0} Salary {1}",
title, salary);
}
}

public class EmployeeList
{
private PersonList persons = new PersonList();
public void Add(Person p)
{
persons.Add(p);
}
public Person PersonRetrieve(int arg)
{
return persons.PersonRetrieve(arg);
}

private JobList jobs = new JobList();
public void Add(Job j)
{
jobs.Add(j);
}
public Job JobRetrieve(int arg)
{
return jobs.JobRetrieve(arg);
}
}
}
}

As far as I can see there are 3 differences:
* some unimportant differences in the data classes
* you only use one method to retrieve data where
I showed two different methods to retrieve data
* your two Add methods does not enforce correlation
between index in person list and job list, which
could be rather disastrous

Arne
 
Z

Zach

On 12/17/2011 4:09 PM, Zach wrote:
On 12/17/2011 9:02 PM, Arne Vajhøj wrote:
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.

<snipped>

Hi Arne, I believe this is shorter:)
does the same thing.
using System;
using System.Collections.Generic;
using System.Text;

namespace analysis1
{
class Program
{
static void Main(string[] args)
{
EmployeeList lst = new EmployeeList();
lst.Add(new Person("A A", "A road 123"));
lst.Add(new Job("Fitter", "10000$"));

lst.Add(new Person("B B", "B ave 456"));
lst.Add(new Job("Tester", "234567$"));

Console.WriteLine(lst.PersonRetrieve(0).PersonString());
Console.WriteLine(lst.JobRetrieve(0).JobString());
Console.WriteLine(lst.PersonRetrieve(1).PersonString());
Console.WriteLine(lst.JobRetrieve(1).JobString());

Console.ReadKey();
}

public class PersonList
{
private List<Person> people = new List<Person>();
public void Add(Person p) { people.Add(p); }
public Person this[int px] { get { return people[px]; }
set { people[px] = value; } }
public Person PersonRetrieve(int py) { return people[py]; }
}

public class JobList
{
private List<Job> jobs = new List<Job>();
public void Add(Job j) { jobs.Add(j); }
public Job this[int jx] { get { return jobs[jx]; }
set { jobs[jx] = value; } }
public Job JobRetrieve(int jy) { return jobs[jy]; }
}

public class Person
{
string name;
string address;
public Person(string name, string address)
{
this.name = name;
this.address = address;
}
public string PersonString()
{
return string.Format ("Name {0} Address {1}",
name, address);
}
}

public class Job
{
string title;
string salary;
public Job(string title, string salary)
{
this.title = title;
this.salary = salary;
}
public string JobString()
{
return string.Format("Title {0} Salary {1}",
title, salary);
}
}

public class EmployeeList
{
private PersonList persons = new PersonList();
public void Add(Person p)
{
persons.Add(p);
}
public Person PersonRetrieve(int arg)
{
return persons.PersonRetrieve(arg);
}

private JobList jobs = new JobList();
public void Add(Job j)
{
jobs.Add(j);
}
public Job JobRetrieve(int arg)
{
return jobs.JobRetrieve(arg);
}
}
}
}

As far as I can see there are 3 differences:
* some unimportant differences in the data classes
* you only use one method to retrieve data where
I showed two different methods to retrieve data
* your two Add methods does not enforce correlation
between index in person list and job list, which
could be rather disastrous

Arne

OK thanks, I'll have another look at it.
Zach.
 
Z

Zach

On 12/19/2011 1:17 AM, Arne Vajhøj wrote:
As far as I can see there are 3 differences:
* some unimportant differences in the data classes
* you only use one method to retrieve data where
I showed two different methods to retrieve data
* your two Add methods does not enforce correlation
between index in person list and job list, which
could be rather disastrous

Arne

Arne, Yes indeed, as you point out, data correlation should be ensured.

But if within the larger system there were a module for data
input/retrieval/modification, also ensuring data integrity and
synchronization of the two lists, would that not suffice?

Alternatively, what about the code below? Both lists are added to in
concert, so there can never be a disparity. What is your opinion?

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

namespace analysis1
{
class Program
{
static void Main(string[] args)
{
EmployeeList lst = new EmployeeList();
lst.Add(new Person("A A", "A road 123"), new Job("Fitter",
"10000$"));
lst.Add(new Person("B B", "B ave 456"), new Job("Tester",
"23456$"));
Console.WriteLine(lst.PersonRetrieve(0).PersonString());
Console.WriteLine(lst.JobRetrieve(0).JobString());
Console.WriteLine(lst.PersonRetrieve(1).PersonString());
Console.WriteLine(lst.JobRetrieve(1).JobString());

Console.ReadKey();
}

public class PersonList
{
private List<Person> people = new List<Person>();
public void Add(Person p) { people.Add(p); }
public Person this[int px] { get { return people[px]; } set
{ people[px] = value; } }
public Person PersonRetrieve(int py) { return people[py]; }
}

public class JobList
{
private List<Job> jobs = new List<Job>();
public void Add(Job j) { jobs.Add(j); }
public Job this[int jx] { get { return jobs[jx]; } set {
jobs[jx] = value; } }
public Job JobRetrieve(int jy) { return jobs[jy]; }
}

public class Person
{
string name;
string address;
public Person(string name, string address)
{
this.name = name;
this.address = address;
}
public string PersonString()
{
return string.Format ("Name {0} Address {1}", name,
address);
}
}

public class Job
{
string title;
string salary;
public Job(string title, string salary)
{
this.title = title;
this.salary = salary;
}
public string JobString()
{
return string.Format("Title {0} Salary {1}", title,
salary);
}
}

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 PersonRetrieve(int arg1)
{
return persons.PersonRetrieve(arg1);
}

public Job JobRetrieve(int arg2)
{
return jobs.JobRetrieve(arg2);
}
}
}
}
 
A

Arne Vajhøj

On 12/19/2011 1:17 AM, Arne Vajhøj wrote:
But if within the larger system there were a module for data
input/retrieval/modification, also ensuring data integrity and
synchronization of the two lists, would that not suffice?

Alternatively, what about the code below? Both lists are added to in
concert, so there can never be a disparity. What is your opinion?

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

namespace analysis1
{
class Program
{
static void Main(string[] args)
{
EmployeeList lst = new EmployeeList();
lst.Add(new Person("A A", "A road 123"), new Job("Fitter", "10000$"));
lst.Add(new Person("B B", "B ave 456"), new Job("Tester", "23456$"));
Console.WriteLine(lst.PersonRetrieve(0).PersonString());
Console.WriteLine(lst.JobRetrieve(0).JobString());
Console.WriteLine(lst.PersonRetrieve(1).PersonString());
Console.WriteLine(lst.JobRetrieve(1).JobString());

Console.ReadKey();
}

public class PersonList
{
private List<Person> people = new List<Person>();
public void Add(Person p) { people.Add(p); }
public Person this[int px] { get { return people[px]; } set { people[px]
= value; } }
public Person PersonRetrieve(int py) { return people[py]; }
}

public class JobList
{
private List<Job> jobs = new List<Job>();
public void Add(Job j) { jobs.Add(j); }
public Job this[int jx] { get { return jobs[jx]; } set { jobs[jx] =
value; } }
public Job JobRetrieve(int jy) { return jobs[jy]; }
}

public class Person
{
string name;
string address;
public Person(string name, string address)
{
this.name = name;
this.address = address;
}
public string PersonString()
{
return string.Format ("Name {0} Address {1}", name, address);
}
}

public class Job
{
string title;
string salary;
public Job(string title, string salary)
{
this.title = title;
this.salary = salary;
}
public string JobString()
{
return string.Format("Title {0} Salary {1}", title, salary);
}
}

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 PersonRetrieve(int arg1)
{
return persons.PersonRetrieve(arg1);
}

public Job JobRetrieve(int arg2)
{
return jobs.JobRetrieve(arg2);
}
}
}
}

That will work.

I would still prefer an Employee object over this.

And I would prefer to make Job an attribute of person over
that.

But it should work.

Arne
 
Z

Zach

Arne, thank you for our discussion and the code you suggested. It has
been very informing.

Regards,
Zach
 

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