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 trialYi Ho Wong
6,377 PointsWhy use Point p = x; in the video?
Why use Point p = x; in below code? What is the purpose?
using System;
namespace TreehouseDefense
{
class Game
{
public static void Main()
{
Map map = new Map(8, 5);
Point x = new MapLocation(4, 2);
Point p = x;
Console.WriteLine(x.DistanceTo(5, 5));
Console.WriteLine(x is MapLocation);
Console.WriteLine(x is Point);
Point point = new Point(0, 0);
Console.WriteLine(point is MapLocation);
Console.ReadLine();
}
}
}
1 Answer
Steven Parker
231,268 PointsThat line was simply for demonstration purposes.
When that line was added, on the line above it x was not a Point but a MapLocation. The "Point p = x;
" line was added to show that a MapLocation could be assigned to a Point.
After the demonstration, x was changed to be a Point on the line above (as shown in your code here), but the assignment of p was never removed.
Yi Ho Wong
6,377 PointsYi Ho Wong
6,377 PointsThanks for the answer! :)