1
public ICommand ChangeLangCommand => new DelegateCommand(this.ChangeLangClick);

I get this compiler error, marked on the => arrow:

Error   1   ; expected

Am I using the wrong compiler version somehow? How can I check this?

10
  • 2
    I don't think it is caused by this line, have you checked the lines above make sure they're all terminated? Commented Aug 30, 2016 at 11:09
  • 1
    I think that even with the new compiler a read-only property public ICommand ChangeLangCommand {get;} = new DelegateCommand(this.ChangeLangClick); would be better than a computed property that you are trying to use. Commented Aug 30, 2016 at 11:14
  • 1
    Maybe you want to assign the delegate command instead of doing some half-syntax lambda? public ICommand ChangeLangCommand = new DelegateCommand(this.ChangeLangClick); Commented Aug 30, 2016 at 11:14
  • 4
    @TorKlingberg, That code if for C#6.0 which you can only use in more recent versions of VS. The syntax you showed wont work on VS2013. You can either upgrade your version of VS or refactor your code Commented Aug 30, 2016 at 11:16
  • 2
    Get VS 2015 (update 3 or 4 is latest) Commented Aug 30, 2016 at 11:18

1 Answer 1

1

This is a C# 6.0 feature called expression bodied property

public ICommand ChangeLangCommand => new DelegateCommand(this.ChangeLangClick);

You can either upgrade your compiler (install latest release version of VS2015) or don't use it, as it's equal to getter-only property:

public ICommand ChangeLangCommand
{
    get
    {
        return new DelegateCommand(this.ChangeLangClick);
    }
}

I have feeling, what creating new instance of the command every time property is accessed is wrong, correct code may/would be

public ICommand ChangeLangCommand { get; }

// in constructor
ChangeLangCommand = new DelegateCommand(this.ChangeLangClick);

I think this is also a new feature (to initialize getter-only property from constructor), if this is true, then you can use older syntax:

ICommand _changeLangCommand;
public ICommand ChangeLangCommand
{
    get
    {
        return _changeLangCommand;
    }
}

// in constructor
_changeLangCommand = new DelegateCommand(this.ChangeLangClick);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.