Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C#

Remco de Wilde
Remco de Wilde
9,864 Points

Using instance of one class in other C#

During the c# training, the trainer uses the instance of class point in other classes. I get the way the classes work, but i don't get the concept of using classes in other classes. Maybe i missed something?

class void Point (int x, int y)

class void MapLocation (Point point)

can anyone explain this concept

Thanks Remco

2 Answers

Hello

You have a class called Car .........  assume for now that the car has an attribute of Type Driver  ... someone has to drive the car ... right?   no it not a driver-less car ... yet :-)

You have Class called Driver  .........  just for demo

class Car(){
    private Driver driver;

    //constructor
    public Car(Driver driver) {
       this driver = driver;   //put a driver in a car
    }
}



class Driver(){
.
.
.
.
}


Driver meDriver = new Driver()
Car myCar  = new Car(meDriver) /// getting myself a Car :-)


same thing with the Map and Point.   A Map ia a Class that takes a Point object or objects as attributes.

Hope this help 

the code above is pseudo code for demo only.

Thanks
Remco de Wilde
Remco de Wilde
9,864 Points

Thanks now i have a visual.