简体   繁体   English

错误CS1056:意外字符'$'Xamarin Studio

[英]Error CS1056: Unexpected character '$' Xamarin Studio

I had a Xamarin Project on Visual Studio 2015, for some reason I moved it over to latest version of Xamarin Studio (based on MonoDevelop), and I'm getting this error: 我在Visual Studio 2015上有一个Xamarin项目,由于某种原因,我将其移至最新版本的Xamarin Studio(基于MonoDevelop),但出现此错误:

Error CS1056: Unexpected character '$' (CS1056)

Here's where it's happening: 这是发生的地方:

...
        public override string ToString()
        {
            return $"{Title}";
        }

I'm using the new feature of C# 6.0 called "String Interpolation". 我正在使用C#6.0的新功能,称为“字符串插值”。 My code worked fine on Visual Studio 2015 , why am I getting this error?? 我的代码在Visual Studio 2015上运行良好 ,为什么会出现此错误?

Looks like there is a setting inside the project properties that are controlling the ability to use C# 6 features. 看起来项目属性中有一个设置正在控制使用C#6功能的能力。

Double-click every project involved to open the Project Options, go to Build > General [> C# (for PCL projects]. From there, choose Version 6 under C# Language Version. 双击每个涉及的项目以打开“项目选项”,依次转到“构建”>“常规” [> C#(对于PCL项目)。

Example for platform projects 平台项目示例

为平台项目选择C#语言版本。

Example for PCL projects (note the tab switch needed) PCL项目示例(请注意需要使用选项卡开关)

为PCL项目选择C#语言版本。

The problem can lie in a bug in some editors that mixes Unicode with ascii. 问题可能出在某些将Unicode与ascii混合使用的编辑器中。 This makes everything look correct in visual studio but when opened in another editor it can be seen that the file is corrupted. 这使所有内容在Visual Studio中看起来都是正确的,但是在其他编辑器中打开时,可以看到文件已损坏。

The current version of Xamarin Studio does not support C#6.0 features, including String Interpolation. 当前版本的Xamarin Studio不支持C#6.0功能,包括字符串插值。

There is a preview release of Xamarin Studio that uses the Microsoft Roslyn compiler and does support string interpolation (do note however that as of January 11th 2016 the current release will not actually BUILD code that uses C#6 features). Xamarin Studio的预览版本使用Microsoft Roslyn编译器并支持字符串插值(但是请注意,自2016年1月11日起,当前版本实际上将不再使用C#6功能来构建代码)。

You can get the preview release here . 您可以在此处获取预览版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM