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 trialJingChi Liang
1,081 PointsError with Path.cs
Path.cs(14,44): error CS0118: TreehouseDefense.Path._path' is a
field' but a `method group' was expected
namespace TreehouseDefense
{
class Path
{
private readonly MapLocation[] _path;
public Path(MapLocation[] path)
{
_path = path;
}
public MapLocation GetLocationAt(int pathStep)
{
return (pathStep < _path.Length) ? _path(pathStep) : null;
}
}
}
1 Answer
Shadab Khan
5,470 PointsHi JingChi,
You need to replace this line in your code :
return (pathStep < _path.Length) ? _path(pathStep) : null;
with following :
return (pathStep < _path.Length) ? _path[pathStep] : null;
If you see carefully, _path is an array of type MapLocation, so we need to use square brackets in the ternary expression, and not parenthesis. In your case you use, _path(pathStep) which makes the compiler think that it is a function call.
Let me know if you have any further questions. All the best!
JingChi Liang
1,081 PointsJingChi Liang
1,081 PointsThanks for your kindly help.