-5

I have problems debugging an old c# application. Compiling and executing give me errors as below:

public partial class Employes
{   
    public string nom { get; set; }  
    public string prenom { get; set; }

    public string FullName => $"{nom} {prenom}"; //Error here

    public Employes()
    {
        this.inscriptions = new HashSet<inscriptions>();
        this.Participants = new HashSet<Participants>();
        this.Roles = new HashSet<Roles>();

    } 
}

Compiling error:

**; expected
$ unexpected**
Camilo Terevinto
  • 31,141
  • 6
  • 88
  • 120
Mat.B
  • 31
  • 1
  • 1
    Which version of C# are you using to compile that code? – Lasse V. Karlsen Aug 09 '17 at 13:26
  • 2
    This application can't be that "old" if it uses c# 6.0 features... – adjan Aug 09 '17 at 13:27
  • 1
    Is that code, the code you posted, also "old", or have you edited this old project? Meaning, did it compile like that at some point but now no longer compiles? Or did you change the code, and now it doesn't compile? – Lasse V. Karlsen Aug 09 '17 at 13:27
  • I assume your VS is *old*, not your app. This feature (string.interpolation) exists only from C#6 upwards, which exists only since VS2015 – MakePeaceGreatAgain Aug 09 '17 at 13:30
  • I use currently Visual studio 2013. the solution was designed by other programmer may be in a different pc. I checked in advanced built setting and only show from default to C#5.0 – Mat.B Aug 09 '17 at 14:10
  • You could change that code to be compliant with C#5.0: `public string FullName { get { return string.Format("{0} {1}", nom, prenom); } }` – Rufus L Aug 09 '17 at 14:37

1 Answers1

3

$ is a C# 6 feature, known as Interpolated Strings. Given that you describe this as an old C# application, perhaps the project is using C# 5 or lower.

EDIT: It seems there is some confusion about the difference between C#/MSBuild and Visual Studio. In case you are using a more recent version of Visual Studio, here's the place to check the C# version (under Project Properties, Build, Advanced):

Vissual Studio Advanced Build Settings

Kirk Larkin
  • 84,915
  • 16
  • 214
  • 203
  • 4
    That assumption is wrong. Visual Studio will target the highest c# version available by default. The real answer is "perhaps you are not opening this with Visual Studio 2015 or newer" – Camilo Terevinto Aug 09 '17 at 13:28
  • 2
    @CamiloTerevinto I've not made an assumption here. You've made the assumption that the project setting has been left at the default - I've simply stated that the project might be targetting C# 5 or lower. – Kirk Larkin Aug 09 '17 at 13:32