I still don't get it!
Let's say that we have some persons.... some persons have a car.
The objects that we have are "person" and "car".
"Person"
-- Create person
-- Haves car
"Car"
-- "Create car"
How can I see (save) which persons have which cars?
Can you please give me an working example???
You should consider the limitations on the relationships first.
Can a person have more than one car?
Can a car be owned by more than one person?
"Which persons have which cars" is also quite impresize.
What exactly do you have on input and what do you have on output?
You obviously want to find owned car(s) when presented with instance of a person.
Do you want to be able to find owner(s) when given instance of a car?
You should also decide what attributes a car and a person have.
I will give a most trivial example with the following assumptions:
1. Car has 3 attributes - make, model and year.
2. Person has 2 attributes - name and car (which can be null).
3. Thus, a person can have at most one car.
4. It is possible for several persons to own the same car.
5. Car object does not know which person(s) own it.
using System;
using System.Collections;
namespace PersonsAndCars
{
class Car
{
public readonly string Make;
public readonly string Model;
public readonly int Year;
public Car( string Make_, string Model_, int Year_ )
{
Make = Make_;
Model = Model_;
Year = Year_;
}
}
class Person
{
public readonly string Name;
public Car Car;
public Person( string Name_, Car Car_ )
{
Name = Name_;
Car = Car_;
}
}
class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main(string[] args)
{
ArrayList People = new ArrayList();
// add person named Test Testov who has a 1999 Toyota Corolla
People.Add(new Person("Test Testov", new Car("Toyota", "Corolla", 1999) ) );
// add person named Poor Darling, who does not have a car
People.Add(new Person("Poor Darling", null) );
// add person named Qwerty Uiopov, who owns 2004 Cadillac DeVille
Car FamilyCadillcac = new Car("Cadillac", "DeVille", 2004);
People.Add( new Person( "Qwerty Uiuopov", FamilyCadillcac ) );
// add person named "Testina Uiuopova" who owns the same car as Qwerty
People.Add( new Person( "Testina Uiopova", FamilyCadillcac ) );
// now print who has what
foreach (Person P in People)
{
if (P.Car != null)
{
Console.WriteLine("{0} has {1} {2} {3}", P.Name,