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 trialAzim Sodikov
11,432 PointsDistanceTo method is giving error!
using System;
namespace TreehouseDefense
{
class Point
{
public readonly int X;
public readonly int Y;
public Point(int x, int y)
{
X = x;
Y = y;
}
public int DistanceTo(int x, int y)
{
int xDiff = X - x;
int yDiff = Y - y;
int xDiffSquared = xDiff * xDiff;
int yDiffSquared = yDiff * yDiff;
}
}
}
I build my local environment to build this, it was working just fine. However, this code is giving a error! Can anybody help me out?
Point.cs(14,20): error CS0161: 'Point.DistanceTo(int, int)': not all code paths return
e [/Users/azimjonsodikov/workspace/BackEnd/Csharp/exercises/DefenseGame/DefenseGame.cs
1 Answer
Seth Kroger
56,413 PointsYou're getting this error because you're saying DistanceTo() returns an int, but you aren't returning any number. It looks like you forgot the final lines to calculate the distance from the squares and return the result.