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# C# Objects Encapsulation and Arrays Ternary If

JingChi Liang
JingChi Liang
1,081 Points

Error with Path.cs

Path.cs(14,44): error CS0118: TreehouseDefense.Path._path' is afield' 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
Shadab Khan
5,470 Points

Hi 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
JingChi Liang
1,081 Points

Thanks for your kindly help.