Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

C# C# Objects Encapsulation with Properties Property Practice

Why am I getting error CS1519?

I tried compiling the code in the Property Practice exercise and I received the Invader.cs(15,22): error CS1519: Unexpected symbol `=>' in class, struct, or interface member declaration error. I even tried adding parenthesis but to no avail.

namespace TreehouseDefense { class Invader { private readonly Path _path; private int _pathStep = 0;

public MapLocation Location => _path.GetLocationAt(_pathStep);

public int Health {get; private set; } = 2;

public bool HasScored {get {return _pathStep >= _path.Length; } }
public bool IsNeutralized => (Health <= 0);

public IsActive => !(IsNeutralized || HasScored);

public Invader(Path path) //Constructor
{
  _path = path;

}

public void Move() => _pathStep += 1;

public void DecreaseHealth(int factor)
{
  Health -= factor;
}

} }

1 Answer

Insert bool before IsActive

public IsActive => !(IsNeutralized || HasScored);

so you have this:

public bool IsActive => !(IsNeutralized || HasScored);