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 with Properties Expression Bodied Members

Amy Kang
Amy Kang
17,188 Points

Unexpected symbol '=>' in class, struct, or interface member declaration

Getting this error when I compile my code with mono on my local machine (Ubuntu).

namespace TreehouseDefense
{
  class Invader
  {
    private readonly Path path;

    private int pathStep = 0;

    public MapLocation Location => this.path.GetLocationAt(this.pathStep);

    public Invader(Path path)
    {
      this.path = path;
    }

    public void Move() => this.pathStep += 1;
  }
}

2 Answers

Steven Parker
Steven Parker
231,236 Points

:point_right: Expression Bodied Members are a recent language addition.

Check your mono/mcs version number. I believe this feature was first available in version 3.8.

The current version is 4.4 — perhaps it's time for an upgrade?

Amy Kang
Amy Kang
17,188 Points

Yep turns out it was my version of C#. I have version 4.0. Just wrote it long form instead.

Rikki MCguire
Rikki MCguire
2,232 Points

you can also write it like this public void Move() { _pathStep += 1;}